LaOsaCoop/Odoo16#127 add product_sale_price_from_pricelist_mrp

This commit is contained in:
Luis 2026-10-15 11:40:35 +02:00
parent 3be3de173e
commit ff7f743be4
15 changed files with 632 additions and 6 deletions

View file

@ -1,6 +1,6 @@
{
"name": "Product Sale Price from Pricelist",
"version": "16.0.1.1.0",
"version": "16.0.1.2.0",
"category": "product",
"summary": "Set sale price from pricelist based on last purchase price",
"description": """

View file

@ -91,6 +91,12 @@ class ProductTemplate(models.Model):
(untaxed_price / template.last_purchase_price_received) - 1.0
) * 100.0
def _get_theoritical_price_surcharge(self):
"""Untaxed amount added to the pricelist price, after the margin and
before taxes and rounding. Hook for other modules."""
self.ensure_one()
return 0.0
def _compute_theoritical_price(self):
pricelist_obj = self.env["product.pricelist"]
pricelist_id = (
@ -119,14 +125,14 @@ class ProductTemplate(models.Model):
)
% template.name
)
untaxed_price = (
partial_price[template.product_variant_id.id]["value"] or 0.0
) + template._get_theoritical_price_surcharge()
tax_price = template.taxes_id.compute_all(
partial_price[template.product_variant_id.id]["value"] or 0.0,
untaxed_price,
handle_price_include=False,
)
price_with_taxes = (
tax_price["taxes"][0]["amount"]
+ partial_price[template.product_variant_id.id]["value"]
)
price_with_taxes = tax_price["taxes"][0]["amount"] + untaxed_price
# Round to configurable step (defined on the pricelist)
step = pricelist.price_rounding_step
if step:

View file

@ -0,0 +1 @@
from . import test_theoritical_price

View file

@ -0,0 +1,56 @@
# Copyright 2026 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestTheoriticalPrice(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
pricelist = cls.env["product.pricelist"].create(
{
"name": "Automatic",
"item_ids": [
(
0,
0,
{
"applied_on": "3_global",
"compute_price": "formula",
"base": "last_purchase_price",
"price_discount": -20.0,
},
)
],
}
)
cls.env["ir.config_parameter"].sudo().set_param(
"product_sale_price_from_pricelist.product_pricelist_automatic",
pricelist.id,
)
tax = cls.env["account.tax"].create(
{
"name": "IVA 10%",
"amount": 10.0,
"amount_type": "percent",
"type_tax_use": "sale",
"price_include": False,
"country_id": cls.env.ref("base.es").id,
}
)
cls.template = cls.env["product.template"].create(
{
"name": "Bulk product",
"detailed_type": "product",
"taxes_id": [(6, 0, tax.ids)],
"list_price": 1.0,
"last_purchase_price_received": 2.0,
}
)
def test_theoritical_price_without_surcharge(self):
self.assertEqual(self.template._get_theoritical_price_surcharge(), 0.0)
self.template._compute_theoritical_price()
self.assertAlmostEqual(self.template.list_price_theoritical, 2.0 * 1.2 * 1.1)
self.assertTrue(self.template.last_purchase_price_updated)