[MIG] product_contract: Migration to 16.0

This commit is contained in:
Rad0van
2023-06-08 18:22:40 +02:00
committed by Abraham Anes
parent fe8ed89bc6
commit 1b930d402e
10 changed files with 94 additions and 69 deletions

View File

@@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo import Command, api, fields, models
class ContractLine(models.Model):
@@ -17,10 +17,10 @@ class ContractLine(models.Model):
copy=False,
)
def _prepare_invoice_line(self, move_form):
res = super(ContractLine, self)._prepare_invoice_line(move_form)
def _prepare_invoice_line(self):
res = super()._prepare_invoice_line()
if self.sale_order_line_id and res:
res["sale_line_ids"] = [(6, 0, [self.sale_order_line_id.id])]
res["sale_line_ids"] = [Command.set([self.sale_order_line_id.id])]
return res
def _get_auto_renew_rule_type(self):
@@ -37,9 +37,6 @@ class ContractLine(models.Model):
if rec.product_id.is_contract:
rec.update(
{
"recurring_rule_type": rec.product_id.recurring_rule_type,
"recurring_invoicing_type": rec.product_id.recurring_invoicing_type,
"recurring_interval": 1,
"is_auto_renew": rec.product_id.is_auto_renew,
"auto_renew_interval": rec.product_id.auto_renew_interval,
"auto_renew_rule_type": rec.product_id.auto_renew_rule_type,
@@ -51,3 +48,30 @@ class ContractLine(models.Model):
),
}
)
def _set_recurrence_field(self, field):
res = super()._set_recurrence_field(field)
for record in self:
if record.product_id.is_contract and field in record.product_id:
record[field] = record.product_id[field]
return res
@api.depends(
"contract_id.recurring_rule_type", "contract_id.line_recurrence", "product_id"
)
def _compute_recurring_rule_type(self):
return super()._compute_recurring_rule_type()
@api.depends(
"contract_id.recurring_invoicing_type",
"contract_id.line_recurrence",
"product_id",
)
def _compute_recurring_invoicing_type(self):
return super()._compute_recurring_invoicing_type()
@api.depends(
"contract_id.recurring_interval", "contract_id.line_recurrence", "product_id"
)
def _compute_recurring_interval(self):
return super()._compute_recurring_interval()

View File

@@ -68,12 +68,12 @@ class ProductTemplate(models.Model):
self.with_company(company).write(
{"property_contract_template_id": False}
)
super().write(vals)
return super().write(vals)
@api.constrains("is_contract", "type")
def _check_contract_product_type(self):
"""
Contract product should be service type
"""
if self.is_contract and self.type != "service":
if any([product.is_contract and product.type != "service" for product in self]):
raise ValidationError(_("Contract product should be service type"))

View File

@@ -84,8 +84,13 @@ class SaleOrder(models.Model):
raise ValidationError(
_(
"You must specify a contract "
"template for '{}' product in '{}' company."
).format(order_line.product_id.name, rec.company_id.name)
"template for '%(product_name)s' product "
"in '%(company_name)s' company."
)
% {
"product_name": order_line.product_id.name,
"company_name": rec.company_id.name,
}
)
contract_templates |= contract_template
for contract_template in contract_templates:
@@ -112,7 +117,7 @@ class SaleOrder(models.Model):
self.filtered(
lambda order: (order.company_id.create_contract_at_sale_order_confirmation)
).action_create_contract()
return super(SaleOrder, self).action_confirm()
return super().action_confirm()
@api.depends("order_line")
def _compute_contract_count(self):

View File

@@ -43,8 +43,8 @@ class SaleOrderLine(models.Model):
help="Specify if process date is 'from' or 'to' invoicing date",
copy=False,
)
date_start = fields.Date(string="Date Start")
date_end = fields.Date(string="Date End")
date_start = fields.Date()
date_end = fields.Date()
contract_line_id = fields.Many2one(
comodel_name="contract.line",
@@ -93,7 +93,7 @@ class SaleOrderLine(models.Model):
_("You can't upsell or downsell a terminated contract")
)
@api.depends("product_id")
@api.depends("product_id", "order_id.company_id")
def _compute_contract_template_id(self):
for rec in self:
rec.contract_template_id = rec.product_id.with_company(
@@ -269,17 +269,11 @@ class SaleOrderLine(models.Model):
SaleOrderLine, self.filtered(lambda l: not l.contract_id)
).invoice_line_create(invoice_id, qty)
@api.depends(
"qty_invoiced",
"qty_delivered",
"product_uom_qty",
"order_id.state",
"product_id.is_contract",
)
def _get_to_invoice_qty(self):
@api.depends("qty_invoiced", "qty_delivered", "product_uom_qty", "state")
def _compute_qty_to_invoice(self):
"""
sale line linked to contracts must not be invoiced from sale order
"""
res = super()._get_to_invoice_qty()
res = super()._compute_qty_to_invoice()
self.filtered("product_id.is_contract").update({"qty_to_invoice": 0.0})
return res