upgrade v16 addons valores por defecto según la categoría interna

This commit is contained in:
snt 2024-09-04 23:07:41 +02:00
parent 688782abd8
commit 412d897695
88 changed files with 4 additions and 4787 deletions

View file

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

View file

@ -1,57 +0,0 @@
# Copyright (C) 2020: Criptomart (https://criptomart.net)
# @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 api, fields, models
_logger = logging.getLogger(__name__)
class ProductProduct(models.Model):
_inherit = "product.product"
@api.depends(
"standard_price",
"last_purchase_price_received",
"lst_price",
"margin_classification_id",
"margin_classification_id.markup",
"margin_classification_id.price_round",
"margin_classification_id.price_surcharge",
"product_tmpl_id.taxes_id",
"product_tmpl_id.list_price",
)
def _compute_theoretical_multi(self):
res = super()._compute_theoretical_multi()
for product in self:
if product.last_purchase_price_received != 0:
(
product.margin_state,
product.theoretical_price,
product.theoretical_difference,
) = self._get_margin_info(
product.margin_classification_id,
product.taxes_id,
product.name,
product.last_purchase_price_received,
product.lst_price,
)
return res
def use_theoretical_price(self):
for product in self:
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):
_inherit = "product.packaging"
qty = fields.Float(
"Contained Quantity",
help="The total number of products you can have per pallet or box.",
digits="Product Unit of Measure",
)

View file

@ -1,92 +0,0 @@
# Copyright (C) 2020: Criptomart (https://criptomart.net)
# @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 api, fields, models
_logger = logging.getLogger(__name__)
MARGIN_STATE_SELECTION = [
("correct", "Correct Margin"),
("too_cheap", "Too Cheap"),
("too_expensive", "Too Expensive"),
]
class ProductTemplate(models.Model):
_inherit = "product.template"
margin_state = fields.Selection(
string="Theoretical Price State",
compute="_compute_theoretical_multi_template",
selection=MARGIN_STATE_SELECTION,
store=True,
)
to_print_label = fields.Boolean(
string="To print label",
help="""The sale price has been updated on this product
and needs to be updated on the shelf.""",
default=False,
)
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",
)
last_purchase_price_received_compute_type = fields.Selection(
[
("without_discounts", "Without discounts"),
("with_discount", "First discount"),
("with_two_discounts", "Double discount"),
("with_three_discounts", "Triple discount"),
("manual_update", "Manual update"),
],
string="Last purchase price calculation type",
help="""
Choose whether discounts should influence the calculation of the last purchase price.
Select Never update for manual configuration of cost and sale prices.\n
* Without discounts: does not take into account discounts when updating
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
* Manual update: Select this for manual configuration of cost and sale price.
The sales price will not be calculated automatically.
""",
default="without_discounts",
required=True,
)
@api.onchange(
"last_purchase_price_received",
"standard_price",
"taxes_id",
"margin_classification_id",
"list_price",
)
def _onchange_standard_price(self):
res = super()._onchange_standard_price()
if self.last_purchase_price_received != 0:
(
self.margin_state,
self.theoretical_price,
self.theoretical_difference,
) = self.env["product.product"]._get_margin_info(
self.margin_classification_id,
self.taxes_id,
self.name,
self.last_purchase_price_received,
self.list_price,
)
return res

View file

@ -1,71 +0,0 @@
# Copyright 2016-2019 Akretion (http://www.akretion.com/)
# Copyright 2020 Criptomart <tech@criptomart.net>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# @author Santi Noreña (<santi@criptomart.net>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo import models
from odoo.tools import float_compare, float_is_zero, float_round
_logger = logging.getLogger(__name__)
class StockMove(models.Model):
_inherit = "stock.move"
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"):
if (
move.product_id.last_purchase_price_received_compute_type
== "with_three_discounts"
):
price_updated = float_round(
move.purchase_line_id.price_subtotal
/ move.purchase_line_id.product_qty,
precision_digits=2,
)
elif (
move.product_id.last_purchase_price_received_compute_type
== "with_discount"
):
price_updated = float_round(
move.purchase_line_id.price_unit
* (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
if float_compare(
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_received: %s for product %s Previous price: %s"
% (
price_updated,
move.product_id.default_code,
move.product_id.last_purchase_price_received,
)
)
# Write last purchase price as SUPERUSER_ID
# warehouse manager may not have the right to write on products
move.product_id.with_company(move.company_id.id).sudo().write(
{"last_purchase_price_received": price_updated}
)
return res