-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
268dada
commit 44812ed
Showing
8 changed files
with
154 additions
and
144 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
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,38 @@ | ||
# Copyright 2020 Coop IT Easy SCRL fs | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
def write(self, vals): | ||
if self.env["ir.config_parameter"].get_param( | ||
"beesdoo_product.auto_write_suggested_price" | ||
): | ||
purchase_price = vals.get("purchase_price") | ||
if purchase_price and purchase_price != self.purchase_price: | ||
# force update of purchase_price (which actually modifies the | ||
# suppliers’ price) to ensure that the next computations that | ||
# depend on it are correct. there are 3 things to do: | ||
# 1. set value in cache | ||
with self.env.do_in_draft(): | ||
self.purchase_price = purchase_price | ||
# 2. call inverse compute method | ||
self._inverse_purchase_price() | ||
# 3. remove the value from vals, to avoid the process to happen a | ||
# second time | ||
del vals["purchase_price"] | ||
|
||
# Important note: The list price is _only_ changed here if the | ||
# `purchase_price` field of the product is changed. If the | ||
# `price` field of the supplierinfo changes normally, the list price | ||
# here is NOT automatically affected. | ||
self.adapt_list_price(vals) | ||
|
||
list_price = vals.get("list_price") | ||
if list_price and list_price != self.list_price: | ||
vals["list_price_write_date"] = fields.Datetime.now() | ||
|
||
super().write(vals) |
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
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