# 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).


from odoo import api, fields, models


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):
        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,
                )

    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


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",
    )
