product_update_price_last_purchase: add double discount to compute options

This commit is contained in:
Luis 2024-01-18 17:09:34 +01:00
parent b16d09ded7
commit 39dd06bacc
7 changed files with 19 additions and 50 deletions

View file

@ -22,7 +22,6 @@
"data": [
"views/actions.xml",
"views/product_view.xml",
"views/res_config.xml",
],
"installable": True,
}

View file

@ -1,4 +1,3 @@
from . import product_template
from . import product_product
from . import res_config
from . import stock_move

View file

@ -41,10 +41,10 @@ class ProductProduct(models.Model):
return res
def use_theoretical_price(self):
res = super().use_theoretical_price()
for product in self:
product.to_print_label = True
return res
if product.last_purchase_price_received_compute_type != "manual_update":
product.lst_price = product.theoretical_price
product.to_print_label = True
class ProductPackaging(models.Model):

View file

@ -45,6 +45,7 @@ class ProductTemplate(models.Model):
[
("without_discounts", "Without discounts"),
("with_discount", "First discount"),
("with_two_discounts", "Double discount"),
("with_three_discounts", "Triple discount"),
("manual_update", "Manual update"),
],
@ -56,6 +57,8 @@ class ProductTemplate(models.Model):
the last purchase price.\n
* First discount: take into account only first discount when updating
the last purchase price.\n
* Double discount: take into account two first discounts when updating
the last purchase price.\n
* Triple discount: take into account all discounts when updating
the last purchase price.
Needs "Purchase Triple Discount" OCA module.\n

View file

@ -1,12 +0,0 @@
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
product_pricelist_automatic = fields.Many2one(
required=False,
comodel_name="product.pricelist",
string="Pricelist applied to automatic calculation of sales price",
config_parameter="product_update_price_last_purchase.product_pricelist_automatic",
)

View file

@ -18,6 +18,7 @@ class StockMove(models.Model):
def product_price_update_before_done(self):
res = super(StockMove, self).product_price_update_before_done()
for move in self.filtered(lambda move: move.location_id.usage == "supplier"):
_logger.warning("move: %s" % move)
if (
move.product_id.last_purchase_price_received_compute_type
== "with_three_discounts"
@ -36,6 +37,17 @@ class StockMove(models.Model):
* (1 - move.purchase_line_id.discount / 100),
precision_digits=2,
)
elif (
move.product_id.last_purchase_price_received_compute_type
== "with_two_discounts"
):
price_updated = float_round(
move.purchase_line_id.price_unit
* (1 - move.purchase_line_id.discount / 100)
* (1 - move.purchase_line_id.discount2 / 100),
precision_digits=2,
)
else:
price_updated = move.purchase_line_id.price_unit
@ -57,4 +69,4 @@ class StockMove(models.Model):
move.product_id.with_company(move.company_id.id).sudo().write(
{"last_purchase_price_received": price_updated}
)
return res
return res

View file

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record
id="res_config_settings_view_form__compute_pvp_pricelist"
model="ir.ui.view"
>
<field
name="name"
>product.update.price.last.purchase.res.config.settings.form</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="120" />
<field name="inherit_id" ref="sale.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='pricing_setting_container']" position="inside">
<div
class="col-12 col-lg-6 o_setting_box"
name="update_price_settigs_container"
>
<div class="o_setting_right_pane">
<label
for="product_pricelist_automatic"
string="PVP Pricelist"
/>
<field name="product_pricelist_automatic" />
</div>
</div>
</xpath>
</field>
</record>
</data>
</odoo>