product_sale_price_from_pricelist: rename field to fix conflict with OCA/purchase_last_price_info
This commit is contained in:
parent
aeb102fb34
commit
3ba962653d
5 changed files with 15 additions and 20 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,10 @@
|
|||
# @author Santi Noreña (<santi@criptomart.net>)
|
||||
# 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(
|
||||
_(
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<field name="inherit_id" ref="product.product_template_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//label[@for='list_price']" position="before">
|
||||
<field name="last_purchase_price"
|
||||
<field name="last_purchase_price_received"
|
||||
widget="monetary"
|
||||
options="{'currency_field': 'currency_id', 'field_digits': True}"
|
||||
attrs="{'readonly': 0}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue