- Remove redundant string= from 17 field definitions where name matches string value (W8113) - Convert @staticmethod to instance methods in selection methods for proper self.env._() access - Fix W8161 (prefer-env-translation) by using self.env._() instead of standalone _() - Fix W8301/W8115 (translation-not-lazy) by proper placement of % interpolation outside self.env._() - Remove unused imports of odoo._ from group_order.py and sale_order_extension.py - All OCA linting warnings in website_sale_aplicoop main models are now resolved Changes: - website_sale_aplicoop/models/group_order.py: 21 field definitions cleaned - website_sale_aplicoop/models/sale_order_extension.py: 5 field definitions cleaned + @staticmethod conversion - Consistent with OCA standards for addon submission
74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
# Copyright 2017-19 Tecnativa - David Vidal
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
from odoo import api
|
|
from odoo import fields
|
|
from odoo import models
|
|
|
|
|
|
class PurchaseOrderLine(models.Model):
|
|
_name = "purchase.order.line"
|
|
_inherit = ["purchase.triple.discount.mixin", "purchase.order.line"]
|
|
|
|
@api.depends("product_qty", "product_uom", "company_id")
|
|
def _compute_price_unit_and_date_planned_and_name(self):
|
|
res = super()._compute_price_unit_and_date_planned_and_name()
|
|
self._compute_discounts()
|
|
return res
|
|
|
|
def _compute_discounts(self):
|
|
for line in self:
|
|
if not line.company_id or not line.product_id or line.invoice_lines:
|
|
continue
|
|
params = {"order_id": line.order_id}
|
|
seller = line.product_id._select_seller(
|
|
partner_id=line.partner_id,
|
|
quantity=line.product_qty,
|
|
date=line.order_id.date_order
|
|
and line.order_id.date_order.date()
|
|
or fields.Date.context_today(line),
|
|
uom_id=line.product_uom,
|
|
params=params,
|
|
)
|
|
if not seller:
|
|
continue
|
|
line.update(
|
|
{
|
|
fname: seller[fname] or 0.0
|
|
for fname in self._get_multiple_discount_field_names()
|
|
}
|
|
)
|
|
|
|
def _prepare_account_move_line(self, move=False):
|
|
self.ensure_one()
|
|
res = super()._prepare_account_move_line(move)
|
|
res.update(
|
|
{fname: self[fname] for fname in self._get_multiple_discount_field_names()}
|
|
)
|
|
return res
|
|
|
|
@api.model
|
|
def _prepare_purchase_order_line(
|
|
self, product_id, product_qty, product_uom, company_id, supplier, po
|
|
):
|
|
res = super()._prepare_purchase_order_line(
|
|
product_id, product_qty, product_uom, company_id, supplier, po
|
|
)
|
|
today = fields.Date.today()
|
|
partner = supplier.partner_id
|
|
uom_po_qty = product_uom._compute_quantity(
|
|
product_qty, product_id.uom_po_id, rounding_method="HALF-UP"
|
|
)
|
|
seller = product_id.with_company(company_id)._select_seller(
|
|
partner_id=partner,
|
|
quantity=uom_po_qty,
|
|
date=po.date_order and max(po.date_order.date(), today) or today,
|
|
uom_id=product_id.uom_po_id,
|
|
)
|
|
res.update(
|
|
{
|
|
fname: seller[fname] or 0.0
|
|
for fname in self._get_multiple_discount_field_names()
|
|
}
|
|
)
|
|
return res
|