[MIG] contract: Migration to 15.0

Most changes are related to the switch from jinja to qweb in mail templates.

Also included:
- convert deprecated onchange that returns a domain and other deprecation warnings
  (see below)
- Add migration scripts from version 14.0 (force the update of the mail templates)
- Fix warnings from pre-commit checks

Fixes depreciation warnings:

- onchange method ContractAbstractContractLine._onchange_product_id returned
  a domain, this is deprecated
- SavepointCase is deprecated:
  https://github.com/odoo/odoo/blob/15.0/odoo/tests/common.py#L742
- assertDictContainsSubset: According to:
  https://stackoverflow.com/questions/20050913/python-unittests-assertdictcontainssubset-recommended-alternative
This commit is contained in:
Jean-Charles Drubay
2021-10-28 18:24:51 +07:00
committed by Pedro M. Baeza
parent 7f620ee1e6
commit 2cae7764c8
22 changed files with 510 additions and 363 deletions

View File

@@ -20,14 +20,22 @@ class ContractAbstractContractLine(models.AbstractModel):
name = fields.Text(string="Description", required=True)
quantity = fields.Float(default=1.0, required=True)
uom_id = fields.Many2one("uom.uom", string="Unit of Measure")
product_uom_category_id = fields.Many2one( # Used for domain of field uom_id
comodel_name="uom.category",
related="product_id.uom_id.category_id",
)
uom_id = fields.Many2one(
comodel_name="uom.uom",
string="Unit of Measure",
domain="[('category_id', '=', product_uom_category_id)]",
)
automatic_price = fields.Boolean(
string="Auto-price?",
help="If this is marked, the price will be obtained automatically "
"applying the pricelist to the product. If not, you will be "
"able to introduce a manual price",
)
specific_price = fields.Float(string="Specific Price")
specific_price = fields.Float()
price_unit = fields.Float(
string="Unit Price",
compute="_compute_price_unit",
@@ -45,7 +53,6 @@ class ContractAbstractContractLine(models.AbstractModel):
" It should be less or equal to 100",
)
sequence = fields.Integer(
string="Sequence",
default=10,
help="Sequence of the contract line when displaying contracts",
)
@@ -76,7 +83,7 @@ class ContractAbstractContractLine(models.AbstractModel):
readonly=False,
copy=True,
)
last_date_invoiced = fields.Date(string="Last Date Invoiced")
last_date_invoiced = fields.Date()
is_canceled = fields.Boolean(string="Canceled", default=False)
is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
auto_renew_interval = fields.Integer(
@@ -157,6 +164,7 @@ class ContractAbstractContractLine(models.AbstractModel):
def _compute_date_start(self):
self._set_recurrence_field("date_start")
# pylint: disable=missing-return
@api.depends("contract_id.recurring_next_date", "contract_id.line_recurrence")
def _compute_recurring_next_date(self):
super()._compute_recurring_next_date()
@@ -232,13 +240,7 @@ class ContractAbstractContractLine(models.AbstractModel):
@api.onchange("product_id")
def _onchange_product_id(self):
if not self.product_id:
return {"domain": {"uom_id": []}}
vals = {}
domain = {
"uom_id": [("category_id", "=", self.product_id.uom_id.category_id.id)]
}
if not self.uom_id or (
self.product_id.uom_id.category_id.id != self.uom_id.category_id.id
):
@@ -257,4 +259,3 @@ class ContractAbstractContractLine(models.AbstractModel):
vals["name"] = self.product_id.get_product_multiline_description_sale()
vals["price_unit"] = product.price
self.update(vals)
return {"domain": domain}

View File

@@ -89,6 +89,7 @@ class ContractContract(models.Model):
string="Invoicing contact",
comodel_name="res.partner",
ondelete="restrict",
domain="['|',('id', 'parent_of', partner_id), ('id', 'child_of', partner_id)]",
)
partner_id = fields.Many2one(
comodel_name="res.partner", inverse="_inverse_partner_id", required=True
@@ -299,7 +300,7 @@ class ContractContract(models.Model):
@api.depends(
"contract_line_ids.recurring_next_date",
"contract_line_ids.is_canceled",
)
) # pylint: disable=missing-return
def _compute_recurring_next_date(self):
for contract in self:
recurring_next_date = contract.contract_line_ids.filtered(
@@ -371,15 +372,6 @@ class ContractContract(models.Model):
else:
self.payment_term_id = partner.property_payment_term_id
self.invoice_partner_id = self.partner_id.address_get(["invoice"])["invoice"]
return {
"domain": {
"invoice_partner_id": [
"|",
("id", "parent_of", self.partner_id.id),
("id", "child_of", self.partner_id.id),
]
}
}
def _convert_contract_lines(self, contract):
self.ensure_one()
@@ -416,8 +408,14 @@ class ContractContract(models.Model):
)
if not journal:
raise ValidationError(
_("Please define a %s journal for the company '%s'.")
% (self.contract_type, self.company_id.name or "")
_(
"Please define a %(contract_type)s journal "
"for the company '%(company)s'."
)
% {
"contract_type": self.contract_type,
"company": self.company_id.name or "",
}
)
invoice_type = "out_invoice"
if self.contract_type == "purchase":
@@ -566,10 +564,16 @@ class ContractContract(models.Model):
self.message_post(
body=_(
"Contract manually invoiced: "
'<a href="#" data-oe-model="%s" data-oe-id="%s">Invoice'
"<a"
' href="#" data-oe-model="%(model_name)s" '
' data-oe-id="%(rec_id)s"'
">Invoice"
"</a>"
)
% (invoice._name, invoice.id)
% {
"model_name": invoice._name,
"rec_id": invoice.id,
}
)
return invoice

View File

@@ -22,9 +22,7 @@ class ContractLine(models.Model):
]
_order = "sequence,id"
sequence = fields.Integer(
string="Sequence",
)
sequence = fields.Integer()
contract_id = fields.Many2one(
comodel_name="contract.contract",
string="Contract",
@@ -44,7 +42,6 @@ class ContractLine(models.Model):
date_start = fields.Date(required=True)
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
termination_notice_date = fields.Date(
string="Termination notice date",
compute="_compute_termination_notice_date",
store=True,
copy=False,
@@ -72,7 +69,6 @@ class ContractLine(models.Model):
help="Contract Line origin of this one.",
)
manual_renew_needed = fields.Boolean(
string="Manual renew needed",
default=False,
help="This flag is used to make a difference between a definitive stop"
"and temporary one for which a user is not able to plan a"
@@ -92,7 +88,6 @@ class ContractLine(models.Model):
string="Un-Cancel allowed?", compute="_compute_allowed"
)
state = fields.Selection(
string="State",
selection=[
("upcoming", "Upcoming"),
("in-progress", "In-progress"),
@@ -109,12 +104,11 @@ class ContractLine(models.Model):
related="contract_id.active",
store=True,
readonly=True,
default=True,
)
@api.depends(
"last_date_invoiced", "date_start", "date_end", "contract_id.last_date_invoiced"
)
) # pylint: disable=missing-return
def _compute_next_period_date_start(self):
"""Rectify next period date start if another line in the contract has been
already invoiced previously when the recurrence is by contract.
@@ -696,15 +690,15 @@ class ContractLine(models.Model):
)
if post_message:
msg = _(
"""Contract line for <strong>{product}</strong>
"""Contract line for <strong>%(product)s</strong>
stopped: <br/>
- <strong>End</strong>: {old_end} -- {new_end}
""".format(
product=rec.name,
old_end=old_date_end,
new_end=rec.date_end,
)
)
- <strong>End</strong>: %(old_end)s -- %(new_end)s
"""
) % {
"product": rec.name,
"old_end": old_date_end,
"new_end": rec.date_end,
}
rec.contract_id.message_post(body=msg)
else:
rec.write(
@@ -770,17 +764,17 @@ class ContractLine(models.Model):
contract_line |= new_line
if post_message:
msg = _(
"""Contract line for <strong>{product}</strong>
"""Contract line for <strong>%(product)s</strong>
planned a successor: <br/>
- <strong>Start</strong>: {new_date_start}
- <strong>Start</strong>: %(new_date_start)s
<br/>
- <strong>End</strong>: {new_date_end}
""".format(
product=rec.name,
new_date_start=new_line.date_start,
new_date_end=new_line.date_end,
)
)
- <strong>End</strong>: %(new_date_end)s
"""
) % {
"product": rec.name,
"new_date_start": new_line.date_start,
"new_date_end": new_line.date_end,
}
rec.contract_id.message_post(body=msg)
return contract_line
@@ -873,17 +867,17 @@ class ContractLine(models.Model):
post_message=False,
)
msg = _(
"""Contract line for <strong>{product}</strong>
"""Contract line for <strong>%(product)s</strong>
suspended: <br/>
- <strong>Suspension Start</strong>: {new_date_start}
- <strong>Suspension Start</strong>: %(new_date_start)s
<br/>
- <strong>Suspension End</strong>: {new_date_end}
""".format(
product=rec.name,
new_date_start=date_start,
new_date_end=date_end,
)
)
- <strong>Suspension End</strong>: %(new_date_end)s
"""
) % {
"product": rec.name,
"new_date_start": date_start,
"new_date_end": date_end,
}
rec.contract_id.message_post(body=msg)
return contract_line
@@ -893,10 +887,13 @@ class ContractLine(models.Model):
for contract in self.mapped("contract_id"):
lines = self.filtered(lambda l, c=contract: l.contract_id == c)
msg = _(
"""Contract line canceled: %s"""
% "<br/>- ".join(
["<strong>%s</strong>" % name for name in lines.mapped("name")]
)
"Contract line canceled: %s",
"<br/>- ".join(
[
"<strong>%(product)s</strong>" % {"product": name}
for name in lines.mapped("name")
]
),
)
contract.message_post(body=msg)
self.mapped("predecessor_contract_line_id").write(
@@ -910,10 +907,13 @@ class ContractLine(models.Model):
for contract in self.mapped("contract_id"):
lines = self.filtered(lambda l, c=contract: l.contract_id == c)
msg = _(
"""Contract line Un-canceled: %s"""
% "<br/>- ".join(
["<strong>%s</strong>" % name for name in lines.mapped("name")]
)
"Contract line Un-canceled: %s",
"<br/>- ".join(
[
"<strong>%(product)s</strong>" % {"product": name}
for name in lines.mapped("name")
]
),
)
contract.message_post(body=msg)
for rec in self:
@@ -1036,17 +1036,17 @@ class ContractLine(models.Model):
new_line = rec._renew_extend_line(date_end)
res |= new_line
msg = _(
"""Contract line for <strong>{product}</strong>
"""Contract line for <strong>%(product)s</strong>
renewed: <br/>
- <strong>Start</strong>: {new_date_start}
- <strong>Start</strong>: %(new_date_start)s
<br/>
- <strong>End</strong>: {new_date_end}
""".format(
product=rec.name,
new_date_start=date_start,
new_date_end=date_end,
)
)
- <strong>End</strong>: %(new_date_end)s
"""
) % {
"product": rec.name,
"new_date_start": date_start,
"new_date_end": date_end,
}
rec.contract_id.message_post(body=msg)
return res

View File

@@ -10,8 +10,8 @@ class ContractModification(models.Model):
_description = "Contract Modification"
_order = "date desc"
date = fields.Date(required=True, string="Date")
description = fields.Text(required=True, string="Description")
date = fields.Date(required=True)
description = fields.Text(required=True)
contract_id = fields.Many2one(
string="Contract",
comodel_name="contract.contract",
@@ -19,10 +19,7 @@ class ContractModification(models.Model):
ondelete="cascade",
index=True,
)
sent = fields.Boolean(
string="Sent",
default=False,
)
sent = fields.Boolean(default=False)
@api.model_create_multi
def create(self, vals_list):

View File

@@ -47,7 +47,7 @@ class ContractRecurrencyBasicMixin(models.AbstractModel):
string="Invoice Every",
help="Invoice every (Days/Week/Month/Year)",
)
date_start = fields.Date(string="Date Start")
date_start = fields.Date()
recurring_next_date = fields.Date(string="Date of Next Invoice")
@api.depends("recurring_invoicing_type", "recurring_rule_type")
@@ -80,7 +80,7 @@ class ContractRecurrencyMixin(models.AbstractModel):
recurring_next_date = fields.Date(
compute="_compute_recurring_next_date", store=True, readonly=False, copy=True
)
date_end = fields.Date(string="Date End", index=True)
date_end = fields.Date(index=True)
next_period_date_start = fields.Date(
string="Next Period Start",
compute="_compute_next_period_date_start",
@@ -89,9 +89,7 @@ class ContractRecurrencyMixin(models.AbstractModel):
string="Next Period End",
compute="_compute_next_period_date_end",
)
last_date_invoiced = fields.Date(
string="Last Date Invoiced", readonly=True, copy=False
)
last_date_invoiced = fields.Date(readonly=True, copy=False)
@api.depends("next_period_date_start")
def _compute_recurring_next_date(self):

View File

@@ -9,7 +9,6 @@ class ResCompany(models.Model):
_inherit = "res.company"
create_new_line_at_contract_line_renew = fields.Boolean(
string="Create New Line At Contract Line Renew",
help="If checked, a new line will be generated at contract line renew "
"and linked to the original one as successor. The default "
"behavior is to extend the end date of the contract by a new "