Browse Source

[FIX] agreement_legal: remove account dependency

pull/301/head
Yves Goldberg 6 years ago
parent
commit
b7b7aa36fa
  1. 2
      agreement_legal/__manifest__.py
  2. 88
      agreement_legal/models/agreement.py
  3. 33
      agreement_legal/models/agreement_recital.py
  4. 34
      agreement_legal/models/agreement_section.py
  5. 7
      agreement_legal/views/agreement.xml

2
agreement_legal/__manifest__.py

@ -12,7 +12,7 @@
"category": "Partner", "category": "Partner",
"license": "AGPL-3", "license": "AGPL-3",
"version": "12.0.1.0.0", "version": "12.0.1.0.0",
"depends": ["contacts", "agreement", "mail", "product"],
"depends": ["contacts", "agreement", "product"],
"data": [ "data": [
"data/ir_sequence.xml", "data/ir_sequence.xml",
"data/module_category.xml", "data/module_category.xml",

88
agreement_legal/models/agreement.py

@ -50,7 +50,7 @@ class Agreement(models.Model):
end_date = fields.Date( end_date = fields.Date(
string="End Date", string="End Date",
track_visibility="onchange", track_visibility="onchange",
help="When the agreement ends."
help="When the agreement ends.",
) )
color = fields.Integer() color = fields.Integer()
active = fields.Boolean( active = fields.Boolean(
@ -121,24 +121,18 @@ class Agreement(models.Model):
help="Date that the contract was terminated.", help="Date that the contract was terminated.",
) )
reviewed_date = fields.Date( reviewed_date = fields.Date(
string="Reviewed Date",
track_visibility="onchange")
string="Reviewed Date", track_visibility="onchange"
)
reviewed_user_id = fields.Many2one( reviewed_user_id = fields.Many2one(
"res.users",
string="Reviewed By",
track_visibility="onchange"
"res.users", string="Reviewed By", track_visibility="onchange"
) )
approved_date = fields.Date( approved_date = fields.Date(
string="Approved Date",
track_visibility="onchange")
string="Approved Date", track_visibility="onchange"
)
approved_user_id = fields.Many2one( approved_user_id = fields.Many2one(
"res.users",
string="Approved By",
track_visibility="onchange"
"res.users", string="Approved By", track_visibility="onchange"
) )
currency_id = fields.Many2one(
"res.currency",
string="Currency")
currency_id = fields.Many2one("res.currency", string="Currency")
partner_id = fields.Many2one( partner_id = fields.Many2one(
"res.partner", "res.partner",
string="Partner", string="Partner",
@ -158,12 +152,10 @@ class Agreement(models.Model):
help="The primary partner contact (If Applicable).", help="The primary partner contact (If Applicable).",
) )
partner_contact_phone = fields.Char( partner_contact_phone = fields.Char(
related="partner_contact_id.phone",
string="Phone"
related="partner_contact_id.phone", string="Phone"
) )
partner_contact_email = fields.Char( partner_contact_email = fields.Char(
related="partner_contact_id.email",
string="Email"
related="partner_contact_id.email", string="Email"
) )
company_contact_id = fields.Many2one( company_contact_id = fields.Many2one(
"res.partner", "res.partner",
@ -172,12 +164,10 @@ class Agreement(models.Model):
help="The primary contact in the company.", help="The primary contact in the company.",
) )
company_contact_phone = fields.Char( company_contact_phone = fields.Char(
related="company_contact_id.phone",
string="Phone"
related="company_contact_id.phone", string="Phone"
) )
company_contact_email = fields.Char( company_contact_email = fields.Char(
related="company_contact_id.email",
string="Email"
related="company_contact_id.email", string="Email"
) )
agreement_type_id = fields.Many2one( agreement_type_id = fields.Many2one(
"agreement.type", "agreement.type",
@ -193,13 +183,7 @@ class Agreement(models.Model):
"agreement types.", "agreement types.",
) )
product_ids = fields.Many2many( product_ids = fields.Many2many(
"product.template",
string="Products & Services")
payment_term_id = fields.Many2one(
"account.payment.term",
string="Payment Term",
track_visibility="onchange",
help="Terms of payments.",
"product.template", string="Products & Services"
) )
assigned_user_id = fields.Many2one( assigned_user_id = fields.Many2one(
"res.users", "res.users",
@ -234,28 +218,16 @@ class Agreement(models.Model):
help="Describes what happens after the contract expires.", help="Describes what happens after the contract expires.",
) )
recital_ids = fields.One2many( recital_ids = fields.One2many(
"agreement.recital",
"agreement_id",
string="Recitals",
copy=True
"agreement.recital", "agreement_id", string="Recitals", copy=True
) )
sections_ids = fields.One2many( sections_ids = fields.One2many(
"agreement.section",
"agreement_id",
string="Sections",
copy=True
"agreement.section", "agreement_id", string="Sections", copy=True
) )
clauses_ids = fields.One2many( clauses_ids = fields.One2many(
"agreement.clause",
"agreement_id",
string="Clauses",
copy=True
"agreement.clause", "agreement_id", string="Clauses", copy=True
) )
appendix_ids = fields.One2many( appendix_ids = fields.One2many(
"agreement.appendix",
"agreement_id",
string="Appendices",
copy=True
"agreement.appendix", "agreement_id", string="Appendices", copy=True
) )
previous_version_agreements_ids = fields.One2many( previous_version_agreements_ids = fields.One2many(
"agreement", "agreement",
@ -275,12 +247,10 @@ class Agreement(models.Model):
"agreement.line", "agreement.line",
"agreement_id", "agreement_id",
string="Products/Services", string="Products/Services",
copy=False
copy=False,
) )
state = fields.Selection( state = fields.Selection(
[("draft", "Draft"),
("active", "Active"),
("inactive", "Inactive")],
[("draft", "Draft"), ("active", "Active"), ("inactive", "Inactive")],
default="draft", default="draft",
track_visibility="always", track_visibility="always",
) )
@ -292,8 +262,8 @@ class Agreement(models.Model):
) )
signed_contract_filename = fields.Char(string="Filename") signed_contract_filename = fields.Char(string="Filename")
signed_contract = fields.Binary( signed_contract = fields.Binary(
string="Signed Document",
track_visibility="always")
string="Signed Document", track_visibility="always"
)
field_id = fields.Many2one( field_id = fields.Many2one(
"ir.model.fields", "ir.model.fields",
string="Field", string="Field",
@ -331,7 +301,8 @@ class Agreement(models.Model):
for agreement in self: for agreement in self:
lang = agreement.partner_id.lang or "en_US" lang = agreement.partner_id.lang or "en_US"
description = MailTemplates.with_context( description = MailTemplates.with_context(
lang=lang)._render_template(
lang=lang
)._render_template(
agreement.description, "agreement", agreement.id agreement.description, "agreement", agreement.id
) )
agreement.dynamic_description = description agreement.dynamic_description = description
@ -342,7 +313,8 @@ class Agreement(models.Model):
for agreement in self: for agreement in self:
lang = agreement.partner_id.lang or "en_US" lang = agreement.partner_id.lang or "en_US"
special_terms = MailTemplates.with_context( special_terms = MailTemplates.with_context(
lang=lang)._render_template(
lang=lang
)._render_template(
agreement.special_terms, "agreement", agreement.id agreement.special_terms, "agreement", agreement.id
) )
agreement.dynamic_special_terms = special_terms agreement.dynamic_special_terms = special_terms
@ -354,8 +326,7 @@ class Agreement(models.Model):
self.sub_object_id = False self.sub_object_id = False
if self.field_id and not self.field_id.relation: if self.field_id and not self.field_id.relation:
self.copyvalue = "${{object.{} or {}}}".format( self.copyvalue = "${{object.{} or {}}}".format(
self.field_id.name,
self.default_value or "''",
self.field_id.name, self.default_value or "''"
) )
self.sub_model_object_field_id = False self.sub_model_object_field_id = False
if self.field_id and self.field_id.relation: if self.field_id and self.field_id.relation:
@ -425,10 +396,9 @@ class Agreement(models.Model):
@api.model @api.model
def create(self, vals): def create(self, vals):
if vals.get("reference", _("New")) == _("New"): if vals.get("reference", _("New")) == _("New"):
vals["reference"] = self.env[
"ir.sequence"].next_by_code("agreement") or _(
"New"
)
vals["reference"] = self.env["ir.sequence"].next_by_code(
"agreement"
) or _("New")
return super(Agreement, self).create(vals) return super(Agreement, self).create(vals)
# Increments the revision on each save action # Increments the revision on each save action

33
agreement_legal/models/agreement_recital.py

@ -12,11 +12,9 @@ class AgreementRecital(models.Model):
name = fields.Char(string="Name", required=True) name = fields.Char(string="Name", required=True)
title = fields.Char( title = fields.Char(
string="Title", string="Title",
help="The title is displayed on the PDF." "The name is not."
help="The title is displayed on the PDF." "The name is not.",
) )
sequence = fields.Integer(
string="Sequence",
default=10)
sequence = fields.Integer(string="Sequence", default=10)
content = fields.Html(string="Content") content = fields.Html(string="Content")
dynamic_content = fields.Html( dynamic_content = fields.Html(
compute="_compute_dynamic_content", compute="_compute_dynamic_content",
@ -24,9 +22,8 @@ class AgreementRecital(models.Model):
help="compute dynamic Content", help="compute dynamic Content",
) )
agreement_id = fields.Many2one( agreement_id = fields.Many2one(
"agreement",
string="Agreement",
ondelete="cascade")
"agreement", string="Agreement", ondelete="cascade"
)
active = fields.Boolean( active = fields.Boolean(
string="Active", string="Active",
default=True, default=True,
@ -65,24 +62,26 @@ class AgreementRecital(models.Model):
template field.""", template field.""",
) )
@api.onchange('field_id', 'sub_model_object_field_id', 'default_value')
@api.onchange("field_id", "sub_model_object_field_id", "default_value")
def onchange_copyvalue(self): def onchange_copyvalue(self):
self.sub_object_id = False self.sub_object_id = False
self.copyvalue = False self.copyvalue = False
self.sub_object_id = False self.sub_object_id = False
if self.field_id and not self.field_id.relation: if self.field_id and not self.field_id.relation:
self.copyvalue = "${object.%s or %s}" % \
(self.field_id.name,
self.default_value or '\'\'')
self.copyvalue = "${{object.{} or {}}}".format(
self.field_id.name, self.default_value or "''"
)
self.sub_model_object_field_id = False self.sub_model_object_field_id = False
if self.field_id and self.field_id.relation: if self.field_id and self.field_id.relation:
self.sub_object_id = self.env['ir.model'].search(
[('model', '=', self.field_id.relation)])[0]
self.sub_object_id = self.env["ir.model"].search(
[("model", "=", self.field_id.relation)]
)[0]
if self.sub_model_object_field_id: if self.sub_model_object_field_id:
self.copyvalue = "${object.%s.%s or %s}" %\
(self.field_id.name,
self.sub_model_object_field_id.name,
self.default_value or '\'\'')
self.copyvalue = "${{object.{}.{} or {}}}".format(
self.field_id.name,
self.sub_model_object_field_id.name,
self.default_value or "''",
)
# compute the dynamic content for mako expression # compute the dynamic content for mako expression
@api.multi @api.multi

34
agreement_legal/models/agreement_section.py

@ -12,17 +12,15 @@ class AgreementSection(models.Model):
name = fields.Char(string="Name", required=True) name = fields.Char(string="Name", required=True)
title = fields.Char( title = fields.Char(
string="Title", string="Title",
help="The title is displayed on the PDF." "The name is not."
help="The title is displayed on the PDF." "The name is not.",
) )
sequence = fields.Integer(string="Sequence") sequence = fields.Integer(string="Sequence")
agreement_id = fields.Many2one( agreement_id = fields.Many2one(
"agreement",
string="Agreement",
ondelete="cascade")
"agreement", string="Agreement", ondelete="cascade"
)
clauses_ids = fields.One2many( clauses_ids = fields.One2many(
"agreement.clause",
"section_id",
string="Clauses")
"agreement.clause", "section_id", string="Clauses"
)
content = fields.Html(string="Section Content") content = fields.Html(string="Section Content")
dynamic_content = fields.Html( dynamic_content = fields.Html(
compute="_compute_dynamic_content", compute="_compute_dynamic_content",
@ -67,24 +65,26 @@ class AgreementSection(models.Model):
template field.""", template field.""",
) )
@api.onchange('field_id', 'sub_model_object_field_id', 'default_value')
@api.onchange("field_id", "sub_model_object_field_id", "default_value")
def onchange_copyvalue(self): def onchange_copyvalue(self):
self.sub_object_id = False self.sub_object_id = False
self.copyvalue = False self.copyvalue = False
self.sub_object_id = False self.sub_object_id = False
if self.field_id and not self.field_id.relation: if self.field_id and not self.field_id.relation:
self.copyvalue = "${object.%s or %s}" % \
(self.field_id.name,
self.default_value or '\'\'')
self.copyvalue = "${{object.{} or {}}}".format(
self.field_id.name, self.default_value or "''"
)
self.sub_model_object_field_id = False self.sub_model_object_field_id = False
if self.field_id and self.field_id.relation: if self.field_id and self.field_id.relation:
self.sub_object_id = self.env['ir.model'].search(
[('model', '=', self.field_id.relation)])[0]
self.sub_object_id = self.env["ir.model"].search(
[("model", "=", self.field_id.relation)]
)[0]
if self.sub_model_object_field_id: if self.sub_model_object_field_id:
self.copyvalue = "${object.%s.%s or %s}" %\
(self.field_id.name,
self.sub_model_object_field_id.name,
self.default_value or '\'\'')
self.copyvalue = "${{object.{}.{} or {}}}".format(
self.field_id.name,
self.sub_model_object_field_id.name,
self.default_value or "''",
)
# compute the dynamic content for mako expression # compute the dynamic content for mako expression
@api.multi @api.multi

7
agreement_legal/views/agreement.xml

@ -130,13 +130,6 @@
<field name="termination_requested"/> <field name="termination_requested"/>
<field name="termination_date"/> <field name="termination_date"/>
</group> </group>
<group name="paymentterm_right" string="Payment Terms">
<field name="term" attrs="{'invisible': [('partner_id', '=', False)]}"/>
<field name="payment_term_id" widget="selection"/>
<field name="renewal_type_id" widget="selection"/>
<field name="increase_type_id" widget="selection"/>
</group>
</group>
<group string="Special Terms"> <group string="Special Terms">
<field name="special_terms" <field name="special_terms"
nolabel="1"/> nolabel="1"/>

Loading…
Cancel
Save