mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract: black, isort, prettier
This commit is contained in:
committed by
Pedro M. Baeza
parent
080bcef159
commit
ae6a8179b7
@@ -34,7 +34,9 @@ class ContractAbstractContractLine(models.AbstractModel):
|
||||
inverse="_inverse_price_unit",
|
||||
)
|
||||
price_subtotal = fields.Float(
|
||||
compute="_compute_price_subtotal", digits="Account", string="Sub Total",
|
||||
compute="_compute_price_subtotal",
|
||||
digits="Account",
|
||||
string="Sub Total",
|
||||
)
|
||||
discount = fields.Float(
|
||||
string="Discount (%)",
|
||||
@@ -69,13 +71,18 @@ class ContractAbstractContractLine(models.AbstractModel):
|
||||
copy=True,
|
||||
)
|
||||
date_start = fields.Date(
|
||||
compute="_compute_date_start", store=True, readonly=False, copy=True,
|
||||
compute="_compute_date_start",
|
||||
store=True,
|
||||
readonly=False,
|
||||
copy=True,
|
||||
)
|
||||
last_date_invoiced = fields.Date(string="Last Date Invoiced")
|
||||
is_canceled = fields.Boolean(string="Canceled", default=False)
|
||||
is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
|
||||
auto_renew_interval = fields.Integer(
|
||||
default=1, string="Renew Every", help="Renew every (Days/Week/Month/Year)",
|
||||
default=1,
|
||||
string="Renew Every",
|
||||
help="Renew every (Days/Week/Month/Year)",
|
||||
)
|
||||
auto_renew_rule_type = fields.Selection(
|
||||
[
|
||||
@@ -184,7 +191,10 @@ class ContractAbstractContractLine(models.AbstractModel):
|
||||
).property_product_pricelist
|
||||
)
|
||||
product = line.product_id.with_context(
|
||||
quantity=line.env.context.get("contract_line_qty", line.quantity,),
|
||||
quantity=line.env.context.get(
|
||||
"contract_line_qty",
|
||||
line.quantity,
|
||||
),
|
||||
pricelist=pricelist.id,
|
||||
partner=line.contract_id.partner_id.id,
|
||||
date=line.env.context.get(
|
||||
|
||||
@@ -25,10 +25,16 @@ class ContractContract(models.Model):
|
||||
"portal.mixin",
|
||||
]
|
||||
|
||||
active = fields.Boolean(default=True,)
|
||||
code = fields.Char(string="Reference",)
|
||||
active = fields.Boolean(
|
||||
default=True,
|
||||
)
|
||||
code = fields.Char(
|
||||
string="Reference",
|
||||
)
|
||||
group_id = fields.Many2one(
|
||||
string="Group", comodel_name="account.analytic.account", ondelete="restrict",
|
||||
string="Group",
|
||||
comodel_name="account.analytic.account",
|
||||
ondelete="restrict",
|
||||
)
|
||||
currency_id = fields.Many2one(
|
||||
compute="_compute_currency_id",
|
||||
@@ -36,7 +42,10 @@ class ContractContract(models.Model):
|
||||
comodel_name="res.currency",
|
||||
string="Currency",
|
||||
)
|
||||
manual_currency_id = fields.Many2one(comodel_name="res.currency", readonly=True,)
|
||||
manual_currency_id = fields.Many2one(
|
||||
comodel_name="res.currency",
|
||||
readonly=True,
|
||||
)
|
||||
contract_template_id = fields.Many2one(
|
||||
string="Contract Template", comodel_name="contract.template"
|
||||
)
|
||||
@@ -77,7 +86,9 @@ class ContractContract(models.Model):
|
||||
ondelete="restrict",
|
||||
)
|
||||
invoice_partner_id = fields.Many2one(
|
||||
string="Invoicing contact", comodel_name="res.partner", ondelete="restrict",
|
||||
string="Invoicing contact",
|
||||
comodel_name="res.partner",
|
||||
ondelete="restrict",
|
||||
)
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name="res.partner", inverse="_inverse_partner_id", required=True
|
||||
@@ -103,10 +114,16 @@ class ContractContract(models.Model):
|
||||
tracking=True,
|
||||
)
|
||||
terminate_comment = fields.Text(
|
||||
string="Termination Comment", readonly=True, copy=False, tracking=True,
|
||||
string="Termination Comment",
|
||||
readonly=True,
|
||||
copy=False,
|
||||
tracking=True,
|
||||
)
|
||||
terminate_date = fields.Date(
|
||||
string="Termination Date", readonly=True, copy=False, tracking=True,
|
||||
string="Termination Date",
|
||||
readonly=True,
|
||||
copy=False,
|
||||
tracking=True,
|
||||
)
|
||||
modification_ids = fields.One2many(
|
||||
comodel_name="contract.modification",
|
||||
@@ -198,7 +215,15 @@ class ContractContract(models.Model):
|
||||
|
||||
invoices = (
|
||||
self.env["account.move.line"]
|
||||
.search([("contract_line_id", "in", self.contract_line_ids.ids,)])
|
||||
.search(
|
||||
[
|
||||
(
|
||||
"contract_line_id",
|
||||
"in",
|
||||
self.contract_line_ids.ids,
|
||||
)
|
||||
]
|
||||
)
|
||||
.mapped("move_id")
|
||||
)
|
||||
# we are forced to always search for this for not losing possible <=v11
|
||||
@@ -221,7 +246,11 @@ class ContractContract(models.Model):
|
||||
return currency or self.journal_id.currency_id or self.company_id.currency_id
|
||||
|
||||
@api.depends(
|
||||
"manual_currency_id", "pricelist_id", "partner_id", "journal_id", "company_id",
|
||||
"manual_currency_id",
|
||||
"pricelist_id",
|
||||
"partner_id",
|
||||
"journal_id",
|
||||
"company_id",
|
||||
)
|
||||
def _compute_currency_id(self):
|
||||
for rec in self:
|
||||
@@ -268,7 +297,8 @@ class ContractContract(models.Model):
|
||||
contract.date_end = max(date_end)
|
||||
|
||||
@api.depends(
|
||||
"contract_line_ids.recurring_next_date", "contract_line_ids.is_canceled",
|
||||
"contract_line_ids.recurring_next_date",
|
||||
"contract_line_ids.is_canceled",
|
||||
)
|
||||
def _compute_recurring_next_date(self):
|
||||
for contract in self:
|
||||
|
||||
@@ -22,7 +22,9 @@ class ContractLine(models.Model):
|
||||
]
|
||||
_order = "sequence,id"
|
||||
|
||||
sequence = fields.Integer(string="Sequence",)
|
||||
sequence = fields.Integer(
|
||||
string="Sequence",
|
||||
)
|
||||
contract_id = fields.Many2one(
|
||||
comodel_name="contract.contract",
|
||||
string="Contract",
|
||||
@@ -32,10 +34,12 @@ class ContractLine(models.Model):
|
||||
ondelete="cascade",
|
||||
)
|
||||
analytic_account_id = fields.Many2one(
|
||||
string="Analytic account", comodel_name="account.analytic.account",
|
||||
string="Analytic account",
|
||||
comodel_name="account.analytic.account",
|
||||
)
|
||||
analytic_tag_ids = fields.Many2many(
|
||||
comodel_name="account.analytic.tag", string="Analytic Tags",
|
||||
comodel_name="account.analytic.tag",
|
||||
string="Analytic Tags",
|
||||
)
|
||||
date_start = fields.Date(required=True)
|
||||
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
|
||||
@@ -132,13 +136,16 @@ class ContractLine(models.Model):
|
||||
self._set_recurrence_field("date_end")
|
||||
|
||||
@api.depends(
|
||||
"date_end", "termination_notice_rule_type", "termination_notice_interval",
|
||||
"date_end",
|
||||
"termination_notice_rule_type",
|
||||
"termination_notice_interval",
|
||||
)
|
||||
def _compute_termination_notice_date(self):
|
||||
for rec in self:
|
||||
if rec.date_end:
|
||||
rec.termination_notice_date = rec.date_end - self.get_relative_delta(
|
||||
rec.termination_notice_rule_type, rec.termination_notice_interval,
|
||||
rec.termination_notice_rule_type,
|
||||
rec.termination_notice_interval,
|
||||
)
|
||||
else:
|
||||
rec.termination_notice_date = False
|
||||
@@ -340,10 +347,10 @@ class ContractLine(models.Model):
|
||||
@api.constrains("is_auto_renew", "successor_contract_line_id", "date_end")
|
||||
def _check_allowed(self):
|
||||
"""
|
||||
logical impossible combination:
|
||||
* a line with is_auto_renew True should have date_end and
|
||||
couldn't have successor_contract_line_id
|
||||
* a line without date_end can't have successor_contract_line_id
|
||||
logical impossible combination:
|
||||
* a line with is_auto_renew True should have date_end and
|
||||
couldn't have successor_contract_line_id
|
||||
* a line without date_end can't have successor_contract_line_id
|
||||
|
||||
"""
|
||||
for rec in self:
|
||||
@@ -412,7 +419,10 @@ class ContractLine(models.Model):
|
||||
)
|
||||
|
||||
@api.onchange(
|
||||
"date_start", "is_auto_renew", "auto_renew_rule_type", "auto_renew_interval",
|
||||
"date_start",
|
||||
"is_auto_renew",
|
||||
"auto_renew_rule_type",
|
||||
"auto_renew_interval",
|
||||
)
|
||||
def _onchange_is_auto_renew(self):
|
||||
"""Date end should be auto-computed if a contract line is set to
|
||||
@@ -420,7 +430,9 @@ class ContractLine(models.Model):
|
||||
for rec in self.filtered("is_auto_renew"):
|
||||
if rec.date_start:
|
||||
rec.date_end = self._get_first_date_end(
|
||||
rec.date_start, rec.auto_renew_rule_type, rec.auto_renew_interval,
|
||||
rec.date_start,
|
||||
rec.auto_renew_rule_type,
|
||||
rec.auto_renew_interval,
|
||||
)
|
||||
|
||||
@api.constrains("is_canceled", "is_auto_renew")
|
||||
@@ -828,7 +840,10 @@ class ContractLine(models.Model):
|
||||
post_message=False,
|
||||
)
|
||||
contract_line |= rec.plan_successor(
|
||||
new_date_start, new_date_end, is_auto_renew, post_message=False,
|
||||
new_date_start,
|
||||
new_date_end,
|
||||
is_auto_renew,
|
||||
post_message=False,
|
||||
)
|
||||
else:
|
||||
new_date_start = date_end + relativedelta(days=1)
|
||||
@@ -847,7 +862,10 @@ class ContractLine(models.Model):
|
||||
post_message=False,
|
||||
)
|
||||
contract_line |= rec.plan_successor(
|
||||
new_date_start, new_date_end, is_auto_renew, post_message=False,
|
||||
new_date_start,
|
||||
new_date_end,
|
||||
is_auto_renew,
|
||||
post_message=False,
|
||||
)
|
||||
msg = _(
|
||||
"""Contract line for <strong>{product}</strong>
|
||||
@@ -856,7 +874,9 @@ class ContractLine(models.Model):
|
||||
<br/>
|
||||
- <strong>Suspension End</strong>: {new_date_end}
|
||||
""".format(
|
||||
product=rec.name, new_date_start=date_start, new_date_end=date_end,
|
||||
product=rec.name,
|
||||
new_date_start=date_start,
|
||||
new_date_end=date_end,
|
||||
)
|
||||
)
|
||||
rec.contract_id.message_post(body=msg)
|
||||
@@ -1017,7 +1037,9 @@ class ContractLine(models.Model):
|
||||
<br/>
|
||||
- <strong>End</strong>: {new_date_end}
|
||||
""".format(
|
||||
product=rec.name, new_date_start=date_start, new_date_end=date_end,
|
||||
product=rec.name,
|
||||
new_date_start=date_start,
|
||||
new_date_end=date_end,
|
||||
)
|
||||
)
|
||||
rec.contract_id.message_post(body=msg)
|
||||
|
||||
@@ -28,7 +28,8 @@ Criteria = namedtuple(
|
||||
],
|
||||
)
|
||||
Allowed = namedtuple(
|
||||
"Allowed", ["plan_successor", "stop_plan_successor", "stop", "cancel", "uncancel"],
|
||||
"Allowed",
|
||||
["plan_successor", "stop_plan_successor", "stop", "cancel", "uncancel"],
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@ class ContractModification(models.Model):
|
||||
ondelete="cascade",
|
||||
index=True,
|
||||
)
|
||||
sent = fields.Boolean(string="Sent", default=False,)
|
||||
sent = fields.Boolean(
|
||||
string="Sent",
|
||||
default=False,
|
||||
)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
|
||||
@@ -43,7 +43,9 @@ class ContractRecurrencyBasicMixin(models.AbstractModel):
|
||||
),
|
||||
)
|
||||
recurring_interval = fields.Integer(
|
||||
default=1, string="Invoice Every", help="Invoice every (Days/Week/Month/Year)",
|
||||
default=1,
|
||||
string="Invoice Every",
|
||||
help="Invoice every (Days/Week/Month/Year)",
|
||||
)
|
||||
date_start = fields.Date(string="Date Start")
|
||||
recurring_next_date = fields.Date(string="Date of Next Invoice")
|
||||
@@ -80,10 +82,12 @@ class ContractRecurrencyMixin(models.AbstractModel):
|
||||
)
|
||||
date_end = fields.Date(string="Date End", index=True)
|
||||
next_period_date_start = fields.Date(
|
||||
string="Next Period Start", compute="_compute_next_period_date_start",
|
||||
string="Next Period Start",
|
||||
compute="_compute_next_period_date_start",
|
||||
)
|
||||
next_period_date_end = fields.Date(
|
||||
string="Next Period End", compute="_compute_next_period_date_end",
|
||||
string="Next Period End",
|
||||
compute="_compute_next_period_date_end",
|
||||
)
|
||||
last_date_invoiced = fields.Date(
|
||||
string="Last Date Invoiced", readonly=True, copy=False
|
||||
|
||||
@@ -11,5 +11,7 @@ class ContractTag(models.Model):
|
||||
|
||||
name = fields.Char(required=True)
|
||||
company_id = fields.Many2one(
|
||||
"res.company", string="Company", default=lambda self: self.env.company.id,
|
||||
"res.company",
|
||||
string="Company",
|
||||
default=lambda self: self.env.company.id,
|
||||
)
|
||||
|
||||
@@ -10,13 +10,17 @@ class ResPartner(models.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
sale_contract_count = fields.Integer(
|
||||
string="Sale Contracts", compute="_compute_contract_count",
|
||||
string="Sale Contracts",
|
||||
compute="_compute_contract_count",
|
||||
)
|
||||
purchase_contract_count = fields.Integer(
|
||||
string="Purchase Contracts", compute="_compute_contract_count",
|
||||
string="Purchase Contracts",
|
||||
compute="_compute_contract_count",
|
||||
)
|
||||
contract_ids = fields.One2many(
|
||||
comodel_name="contract.contract", inverse_name="partner_id", string="Contracts",
|
||||
comodel_name="contract.contract",
|
||||
inverse_name="partner_id",
|
||||
string="Contracts",
|
||||
)
|
||||
|
||||
def _get_partner_contract_domain(self):
|
||||
@@ -49,8 +53,8 @@ class ResPartner(models.Model):
|
||||
)
|
||||
|
||||
def act_show_contract(self):
|
||||
""" This opens contract view
|
||||
@return: the contract view
|
||||
"""This opens contract view
|
||||
@return: the contract view
|
||||
"""
|
||||
self.ensure_one()
|
||||
contract_type = self._context.get("contract_type")
|
||||
|
||||
Reference in New Issue
Block a user