forked from Vauxoo/addons-vauxoo
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from Vauxoo/15.0
Syncing from upstream Vauxoo/addons-vauxoo (15.0)
- Loading branch information
Showing
10 changed files
with
70 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
sale_margin_percentage/migrations/15.0.1.0.1/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import logging | ||
|
||
from odoo import SUPERUSER_ID, api | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def migrate(cr, version): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
update_margin_threshold(env) | ||
recompute_margin_percent(env) | ||
|
||
|
||
def update_margin_threshold(env): | ||
companies = env["res.company"].search([]) | ||
for company in companies: | ||
company.write({"margin_threshold": company.margin_threshold / 100.0}) | ||
|
||
_logger.info("The margin threshold for %s companies have been updated.", len(companies)) | ||
|
||
|
||
def recompute_margin_percent(env): | ||
order_lines = env["sale.order.line"].search([]) | ||
order_lines._compute_margin() | ||
_logger.info("The margin percentage of %s records have been recomputed.", len(order_lines)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from . import res_company | ||
from . import res_config_settings | ||
from . import sale_order | ||
from . import sale_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
margin_threshold = fields.Float( | ||
default=lambda self: self.env.user.company_id.margin_threshold, help="Limit margin set in sales configuration" | ||
) | ||
purchase_price = fields.Float(readonly=True, help="Price purchase of product") | ||
|
||
@api.depends("price_subtotal", "product_uom_qty", "purchase_price") | ||
def _compute_margin(self): | ||
res = super()._compute_margin() | ||
for line in self: | ||
currency = line.order_id.pricelist_id.currency_id | ||
if not line.product_uom_qty: | ||
line.margin_percent = 0.0 | ||
continue | ||
|
||
if currency.is_zero(line.price_unit) or currency.is_zero(line.price_subtotal): | ||
line.margin_percent = -1.0 | ||
continue | ||
|
||
purchase_price = line.purchase_price or line.product_id.standard_price | ||
if currency.is_zero(purchase_price): | ||
line.margin_percent = 1.0 | ||
continue | ||
|
||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters