diff --git a/product_sale_price_from_pricelist/models/product_pricelist.py b/product_sale_price_from_pricelist/models/product_pricelist.py index e5d8c95..b309ee0 100644 --- a/product_sale_price_from_pricelist/models/product_pricelist.py +++ b/product_sale_price_from_pricelist/models/product_pricelist.py @@ -24,7 +24,9 @@ class ProductPricelist(models.Model): if item_id: item = ProductPricelistItem.browse(item_id) if item.base == "last_purchase_price": - price = ProductProduct.browse(product_id).last_purchase_price + price = ProductProduct.browse( + product_id + ).last_purchase_price_received price = (price - (price * (item.price_discount / 100))) or 0.0 new_res[product_id] = (price, item_id) return new_res diff --git a/product_sale_price_from_pricelist/models/product_pricelist_item.py b/product_sale_price_from_pricelist/models/product_pricelist_item.py index 2c574e1..136ce81 100644 --- a/product_sale_price_from_pricelist/models/product_pricelist_item.py +++ b/product_sale_price_from_pricelist/models/product_pricelist_item.py @@ -9,6 +9,6 @@ class ProductPricelistItem(models.Model): _inherit = "product.pricelist.item" base = fields.Selection( - selection_add=[("last_purchase_price", "Last purchase price")], - ondelete={"last_purchase_price": "set default"}, + selection_add=[("last_purchase_price_received", "Last purchase price")], + ondelete={"last_purchase_price_received": "set default"}, ) diff --git a/product_sale_price_from_pricelist/models/product_template.py b/product_sale_price_from_pricelist/models/product_template.py index 7ec4504..b2a1b01 100644 --- a/product_sale_price_from_pricelist/models/product_template.py +++ b/product_sale_price_from_pricelist/models/product_template.py @@ -2,13 +2,10 @@ # @author Santi NoreƱa () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import logging from odoo import exceptions, models, fields, api, _ from odoo.exceptions import UserError -_logger = logging.getLogger(__name__) - class ProductTemplate(models.Model): _inherit = "product.template" @@ -24,10 +21,9 @@ class ProductTemplate(models.Model): readonly=True, company_dependent=True, ) - last_purchase_price = fields.Float( + last_purchase_price_received = fields.Float( string="Last purchase price", help="The last price at which the product was purchased. It is used as the base price field for calculating the product sale price.", - readonly=True, digits="Product Price", company_dependent=True, ) @@ -61,9 +57,6 @@ class ProductTemplate(models.Model): pricelist = pricelist_obj.browse(int(pricelist_id)) if pricelist: for template in self: - _logger.debug(("company: %s" % self.env.company)) - _logger.debug("compute pre price : %s" % template.last_purchase_price) - if ( template.name and template.id @@ -73,10 +66,8 @@ class ProductTemplate(models.Model): partial_price = template.product_variant_id._get_price( qty=1, pricelist=pricelist ) - _logger.debug("partial price : %s" % partial_price) template.list_price_theoritical = partial_price["value"] template.last_purchase_price_updated = True - _logger.debug("final price : %s" % template.list_price_theoritical) else: raise UserError( _( diff --git a/product_sale_price_from_pricelist/models/stock_move.py b/product_sale_price_from_pricelist/models/stock_move.py index 34c8c2b..419eb21 100644 --- a/product_sale_price_from_pricelist/models/stock_move.py +++ b/product_sale_price_from_pricelist/models/stock_move.py @@ -47,19 +47,21 @@ class StockMove(models.Model): price_updated = move.purchase_line_id.price_unit if float_compare( - move.product_id.last_purchase_price, price_updated, precision_digits=2 + move.product_id.last_purchase_price_received, + price_updated, + precision_digits=2, ) and not float_is_zero(move.quantity_done, precision_digits=3): _logger.info( - "Update last_purchase_price: %s for product %s Previous price: %s" + "Update last_purchase_price_received: %s for product %s Previous price: %s" % ( price_updated, move.product_id.default_code, - move.product_id.last_purchase_price, + move.product_id.last_purchase_price_received, ) ) - move.product_id.with_company(move.company_id).last_purchase_price = ( - price_updated - ) + move.product_id.with_company( + move.company_id + ).last_purchase_price_received = price_updated move.product_id.with_company( move.company_id ).product_tmpl_id._compute_theoritical_price() diff --git a/product_sale_price_from_pricelist/views/product_view.xml b/product_sale_price_from_pricelist/views/product_view.xml index 3db44de..fdd4675 100644 --- a/product_sale_price_from_pricelist/views/product_view.xml +++ b/product_sale_price_from_pricelist/views/product_view.xml @@ -10,7 +10,7 @@ -