product_sale_price_from_pricelist: rename field to fix conflict with OCA/purchase_last_price_info

This commit is contained in:
Luis 2025-02-05 12:51:54 +01:00
parent aeb102fb34
commit 3ba962653d
5 changed files with 15 additions and 20 deletions

View file

@ -24,7 +24,9 @@ class ProductPricelist(models.Model):
if item_id: if item_id:
item = ProductPricelistItem.browse(item_id) item = ProductPricelistItem.browse(item_id)
if item.base == "last_purchase_price": 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 price = (price - (price * (item.price_discount / 100))) or 0.0
new_res[product_id] = (price, item_id) new_res[product_id] = (price, item_id)
return new_res return new_res

View file

@ -9,6 +9,6 @@ class ProductPricelistItem(models.Model):
_inherit = "product.pricelist.item" _inherit = "product.pricelist.item"
base = fields.Selection( base = fields.Selection(
selection_add=[("last_purchase_price", "Last purchase price")], selection_add=[("last_purchase_price_received", "Last purchase price")],
ondelete={"last_purchase_price": "set default"}, ondelete={"last_purchase_price_received": "set default"},
) )

View file

@ -2,13 +2,10 @@
# @author Santi Noreña (<santi@criptomart.net>) # @author Santi Noreña (<santi@criptomart.net>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import exceptions, models, fields, api, _ from odoo import exceptions, models, fields, api, _
from odoo.exceptions import UserError from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
class ProductTemplate(models.Model): class ProductTemplate(models.Model):
_inherit = "product.template" _inherit = "product.template"
@ -24,10 +21,9 @@ class ProductTemplate(models.Model):
readonly=True, readonly=True,
company_dependent=True, company_dependent=True,
) )
last_purchase_price = fields.Float( last_purchase_price_received = fields.Float(
string="Last purchase price", 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.", 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", digits="Product Price",
company_dependent=True, company_dependent=True,
) )
@ -61,9 +57,6 @@ class ProductTemplate(models.Model):
pricelist = pricelist_obj.browse(int(pricelist_id)) pricelist = pricelist_obj.browse(int(pricelist_id))
if pricelist: if pricelist:
for template in self: for template in self:
_logger.debug(("company: %s" % self.env.company))
_logger.debug("compute pre price : %s" % template.last_purchase_price)
if ( if (
template.name template.name
and template.id and template.id
@ -73,10 +66,8 @@ class ProductTemplate(models.Model):
partial_price = template.product_variant_id._get_price( partial_price = template.product_variant_id._get_price(
qty=1, pricelist=pricelist qty=1, pricelist=pricelist
) )
_logger.debug("partial price : %s" % partial_price)
template.list_price_theoritical = partial_price["value"] template.list_price_theoritical = partial_price["value"]
template.last_purchase_price_updated = True template.last_purchase_price_updated = True
_logger.debug("final price : %s" % template.list_price_theoritical)
else: else:
raise UserError( raise UserError(
_( _(

View file

@ -47,19 +47,21 @@ class StockMove(models.Model):
price_updated = move.purchase_line_id.price_unit price_updated = move.purchase_line_id.price_unit
if float_compare( 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): ) and not float_is_zero(move.quantity_done, precision_digits=3):
_logger.info( _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, price_updated,
move.product_id.default_code, 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 = ( move.product_id.with_company(
price_updated move.company_id
) ).last_purchase_price_received = price_updated
move.product_id.with_company( move.product_id.with_company(
move.company_id move.company_id
).product_tmpl_id._compute_theoritical_price() ).product_tmpl_id._compute_theoritical_price()

View file

@ -10,7 +10,7 @@
<field name="inherit_id" ref="product.product_template_form_view" /> <field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//label[@for='list_price']" position="before"> <xpath expr="//label[@for='list_price']" position="before">
<field name="last_purchase_price" <field name="last_purchase_price_received"
widget="monetary" widget="monetary"
options="{'currency_field': 'currency_id', 'field_digits': True}" options="{'currency_field': 'currency_id', 'field_digits': True}"
attrs="{'readonly': 0}" attrs="{'readonly': 0}"