[13.0][MIG] - migration product_contract

This commit is contained in:
sbejaoui
2020-10-24 20:37:58 +02:00
committed by Ilyas
parent 8ac91c2101
commit 417702f3d5
17 changed files with 436 additions and 548 deletions

View File

@@ -2,78 +2,76 @@
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models, _
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ProductTemplate(models.Model):
_inherit = 'product.template'
_inherit = "product.template"
is_contract = fields.Boolean('Is a contract')
is_contract = fields.Boolean("Is a contract")
property_contract_template_id = fields.Many2one(
comodel_name='contract.template',
string='Contract Template',
comodel_name="contract.template",
string="Contract Template",
company_dependent=True,
)
default_qty = fields.Integer(string="Default Quantity", default=1)
recurring_rule_type = fields.Selection(
[
('daily', 'Day(s)'),
('weekly', 'Week(s)'),
('monthly', 'Month(s)'),
('monthlylastday', 'Month(s) last day'),
('quarterly', 'Quarter(s)'),
('semesterly', 'Semester(s)'),
('yearly', 'Year(s)'),
("daily", "Day(s)"),
("weekly", "Week(s)"),
("monthly", "Month(s)"),
("monthlylastday", "Month(s) last day"),
("quarterly", "Quarter(s)"),
("semesterly", "Semester(s)"),
("yearly", "Year(s)"),
],
default='monthly',
string='Invoice Every',
default="monthly",
string="Invoice Every",
help="Specify Interval for automatic invoice generation.",
)
recurring_invoicing_type = fields.Selection(
[('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')],
default='pre-paid',
string='Invoicing type',
[("pre-paid", "Pre-paid"), ("post-paid", "Post-paid")],
default="pre-paid",
string="Invoicing type",
help="Specify if process date is 'from' or 'to' invoicing date",
)
is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
termination_notice_interval = fields.Integer(
default=1, string='Termination Notice Before'
default=1, string="Termination Notice Before"
)
termination_notice_rule_type = fields.Selection(
[('daily', 'Day(s)'), ('weekly', 'Week(s)'), ('monthly', 'Month(s)')],
default='monthly',
string='Termination Notice type',
[("daily", "Day(s)"), ("weekly", "Week(s)"), ("monthly", "Month(s)")],
default="monthly",
string="Termination Notice type",
)
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(
[
('daily', 'Day(s)'),
('weekly', 'Week(s)'),
('monthly', 'Month(s)'),
('yearly', 'Year(s)'),
("daily", "Day(s)"),
("weekly", "Week(s)"),
("monthly", "Month(s)"),
("yearly", "Year(s)"),
],
default='yearly',
string='Renewal type',
default="yearly",
string="Renewal type",
help="Specify Interval for automatic renewal.",
)
@api.multi
def write(self, vals):
if 'is_contract' in vals and vals['is_contract'] is False:
for company in self.env['res.company'].search([]):
if "is_contract" in vals and vals["is_contract"] is False:
for company in self.env["res.company"].search([]):
self.with_context(force_company=company.id).write(
{'property_contract_template_id': False})
{"property_contract_template_id": False}
)
super().write(vals)
@api.constrains('is_contract', 'type')
@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 self.is_contract and self.type != "service":
raise ValidationError(_("Contract product should be service type"))