Browse Source

[IMP] Models and views

pull/196/head
Maxime Chambreuil 6 years ago
parent
commit
7587d07323
  1. 1
      agreement/models/__init__.py
  2. 10
      agreement/models/account.py
  3. 81
      agreement/models/agreement.py
  4. 2
      agreement/models/res_partner.py
  5. 97
      agreement/views/agreement.xml
  6. 7
      agreement/views/menu.xml

1
agreement/models/__init__.py

@ -2,6 +2,7 @@
from . import ( from . import (
res_config_settings, res_config_settings,
account,
agreement, agreement,
agreement_clause, agreement_clause,
agreement_section, agreement_section,

10
agreement/models/account.py

@ -0,0 +1,10 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'
agreement_id = fields.Many2one('agreement', string='Agreement')

81
agreement/models/agreement.py

@ -1,7 +1,7 @@
# Copyright (C) 2018 - TODAY, Pavlov Media # Copyright (C) 2018 - TODAY, Pavlov Media
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, fields, _
from odoo import api, fields, models, _
class Agreement(models.Model): class Agreement(models.Model):
@ -58,26 +58,20 @@ class Agreement(models.Model):
"removing it." "removing it."
) )
company_signed_date = fields.Date( company_signed_date = fields.Date(
string="Company Signed Date",
string="Signed on",
track_visibility='onchange', track_visibility='onchange',
help="Date the contract was signed by Company." help="Date the contract was signed by Company."
) )
customer_signed_date = fields.Date(
string="Customer Signed Date",
partner_signed_date = fields.Date(
string="Signed on",
track_visibility='onchange', track_visibility='onchange',
help="Date the contract was signed by Customer."
help="Date the contract was signed by the Partner."
) )
customer_term = fields.Integer(
string="Customer Term (Months)",
term = fields.Integer(
string="Term (Months)",
track_visibility='onchange', track_visibility='onchange',
help="Number of months this agreement/contract is in effect with "
"customer."
)
vendor_term = fields.Integer(
string="Vendor Term (Months)",
track_visibility='onchange',
help="Number of months this agreement/contract is in effect with "
"vendor."
help="Number of months this agreement/contract is in effect with the "
"partner."
) )
expiration_notice = fields.Integer( expiration_notice = fields.Integer(
string="Exp. Notice (Days)", string="Exp. Notice (Days)",
@ -161,49 +155,48 @@ class Agreement(models.Model):
string="Approved By", string="Approved By",
track_visibility='onchange' track_visibility='onchange'
) )
currency_id = fields.Many2one( currency_id = fields.Many2one(
'res.currency', 'res.currency',
string='Currency' string='Currency'
) )
customer_id = fields.Many2one(
partner_id = fields.Many2one(
'res.partner', 'res.partner',
string="Customer",
string="Partmer",
copy=True, copy=True,
help="The customer this agreement is related to (If Applicable)."
help="The customer or vendor this agreement is related to."
) )
vendor_id = fields.Many2one(
company_partner_id = fields.Many2one(
'res.partner', 'res.partner',
string="Vendor",
string="Company",
copy=True, copy=True,
help="The vendor this agreement is related to (If Applicable)."
default=lambda self: self.env.user.company_id.partner_id
) )
customer_contact_id = fields.Many2one(
partner_contact_id = fields.Many2one(
'res.partner', 'res.partner',
string="Customer Contact",
string="Partner Contact",
copy=True, copy=True,
help="The primary customer contact (If Applicable)."
help="The primary partner contact (If Applicable)."
) )
customer_contact_phone = fields.Char(
related='customer_contact_id.phone',
partner_contact_phone = fields.Char(
related='partner_contact_id.phone',
string="Phone" string="Phone"
) )
customer_contact_email = fields.Char(
related='customer_contact_id.email',
partner_contact_email = fields.Char(
related='partner_contact_id.email',
string="Email" string="Email"
) )
vendor_contact_id = fields.Many2one(
company_contact_id = fields.Many2one(
'res.partner', 'res.partner',
string="Vendor Contact",
string="Company Contact",
copy=True, copy=True,
help="The primary vendor contact (If Applicable)."
help="The primary contact in the company."
) )
vendor_contact_phone = fields.Char(
related='vendor_contact_id.phone',
company_contact_phone = fields.Char(
related='company_contact_id.phone',
string="Phone" string="Phone"
) )
vendor_contact_email = fields.Char(
related='vendor_contact_id.email',
company_contact_email = fields.Char(
related='company_contact_id.email',
string="Email" string="Email"
) )
agreement_type_id = fields.Many2one( agreement_type_id = fields.Many2one(
@ -243,14 +236,14 @@ class Agreement(models.Model):
) )
company_signed_user_id = fields.Many2one( company_signed_user_id = fields.Many2one(
'res.users', 'res.users',
string="Company Signed By",
string="Signed By",
track_visibility='onchange', track_visibility='onchange',
help="The user at our company who authorized/signed the agreement or " help="The user at our company who authorized/signed the agreement or "
"contract." "contract."
) )
customer_signed_user_id = fields.Many2one(
partner_signed_user_id = fields.Many2one(
'res.partner', 'res.partner',
string="Customer Signed By",
string="Signed By",
track_visibility='onchange', track_visibility='onchange',
help="Contact on the account that signed the agreement/contract." help="Contact on the account that signed the agreement/contract."
) )
@ -284,6 +277,12 @@ class Agreement(models.Model):
string="Clauses", string="Clauses",
copy=True copy=True
) )
analytic_id = fields.Many2one('account.analytic.account',
string='Analytic Account', index=True)
analytic_line_ids = fields.One2many('account.analytic.line',
'agreement_id',
string='Revenues and Costs',
copy=False)
previous_version_agreements_ids = fields.One2many( previous_version_agreements_ids = fields.One2many(
'agreement', 'agreement',
'parent_agreement_id', 'parent_agreement_id',
@ -325,11 +324,11 @@ class Agreement(models.Model):
) )
# compute contract_value field # compute contract_value field
@api.depends('total_customer_mrc', 'total_customer_nrc', 'customer_term')
@api.depends('total_customer_mrc', 'total_customer_nrc', 'term')
def _compute_contract_value(self): def _compute_contract_value(self):
for record in self: for record in self:
record.contract_value =\ record.contract_value =\
(record.total_customer_mrc * record.customer_term) +\
(record.total_customer_mrc * record.term) +\
record.total_customer_nrc record.total_customer_nrc
# compute total_company_mrc field # compute total_company_mrc field

2
agreement/models/res_partner.py

@ -6,5 +6,5 @@ from odoo import models, fields
class Partner(models.Model): class Partner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
agreement_ids = fields.One2many('agreement', 'customer_id',
agreement_ids = fields.One2many('agreement', 'partner_id',
string="Agreements") string="Agreements")

97
agreement/views/agreement.xml

@ -8,8 +8,8 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree default_order='name'> <tree default_order='name'>
<field name="name"/> <field name="name"/>
<field name="customer_id"/>
<field name="vendor_id"/>
<field name="partner_id"/>
<field name="company_partner_id"/>
<field name="parent_agreement_id"/> <field name="parent_agreement_id"/>
<field name="agreement_type_id"/> <field name="agreement_type_id"/>
<field name="agreement_subtype_id"/> <field name="agreement_subtype_id"/>
@ -40,7 +40,7 @@
<group> <group>
<field name="reference" readonly="1"/> <field name="reference" readonly="1"/>
<field name="parent_agreement_id" <field name="parent_agreement_id"
domain="[('customer_id', '=', customer_id)]"/>
domain="[('partner_id', '=', partner_id)]"/>
<field name="is_template"/> <field name="is_template"/>
</group> </group>
<group> <group>
@ -62,33 +62,33 @@
nolabel="1"/> nolabel="1"/>
</group> </group>
<group name="parties" string="Parties"> <group name="parties" string="Parties">
<group name="customer_left"
string="Customer">
<group name="partner"
string="Partner">
<div class="o_address_format"> <div class="o_address_format">
<field name="customer_id"
<field name="partner_id"
domain="[('customer', '=', True)]" domain="[('customer', '=', True)]"
context="{'show_address': 1}" context="{'show_address': 1}"
options="{&quot;always_reload&quot;: True}"/> options="{&quot;always_reload&quot;: True}"/>
</div> </div>
</group> </group>
<group name="vendor_right"
string="Vendor">
<group name="company"
string="Company">
<div class="o_address_format"> <div class="o_address_format">
<field name="vendor_id"
domain="[('supplier', '=', True)]"
<field name="company_partner_id"
readonly="1"
context="{'show_address': 1}" context="{'show_address': 1}"
options="{&quot;always_reload&quot;: True}"/> options="{&quot;always_reload&quot;: True}"/>
</div> </div>
</group> </group>
<group name="contact_left" string="Primary Contact">
<field name="customer_contact_id" domain="[('parent_id', '=', customer_id)]" nolabel="1"/>
<field name="customer_contact_phone" widget="phone" readonly="1" nolabel="1"/>
<field name="customer_contact_email" widget="email" readonly="1" nolabel="1"/>
<group name="partner_left" string="Primary Contact">
<field name="partner_contact_id" domain="[('parent_id', '=', partner_id)]" nolabel="1"/>
<field name="partner_contact_phone" widget="phone" readonly="1" nolabel="1"/>
<field name="partner_contact_email" widget="email" readonly="1" nolabel="1"/>
</group> </group>
<group name="contact_right" string="Primary Contact"> <group name="contact_right" string="Primary Contact">
<field name="vendor_contact_id" domain="[('parent_id', '=', vendor_id)]" nolabel="1"/>
<field name="vendor_contact_phone" widget="phone" readonly="1" nolabel="1"/>
<field name="vendor_contact_email" widget="email" readonly="1" nolabel="1"/>
<field name="company_contact_id" domain="[('parent_id', '=', company_partner_id)]" nolabel="1"/>
<field name="company_contact_phone" widget="phone" readonly="1" nolabel="1"/>
<field name="company_contact_email" widget="email" readonly="1" nolabel="1"/>
</group> </group>
</group> </group>
<group name="term_information"> <group name="term_information">
@ -97,13 +97,12 @@
<field name="end_date" required="True" attrs="{'required': [('is_template', '=', False)], 'readonly':[('is_template', '=', True)]}"/> <field name="end_date" required="True" attrs="{'required': [('is_template', '=', False)], 'readonly':[('is_template', '=', True)]}"/>
<field name="expiration_notice"/> <field name="expiration_notice"/>
<field name="change_notice"/> <field name="change_notice"/>
<field name="notification_address_id" domain="['|',('parent_id','=',customer_id),('parent_id','=',vendor_id)]"/>
<field name="notification_address_id" domain="['|', ('parent_id', '=', partner_id), ('parent_id', '=', company_partner_id)]"/>
<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"> <group name="paymentterm_right" string="Payment Terms">
<field name="customer_term" attrs="{'invisible': [('customer_id', '=', False)]}"/>
<field name="vendor_term" attrs="{'invisible': [('vendor_id', '=', False)]}"/>
<field name="term" attrs="{'invisible': [('partner_id', '=', False)]}"/>
<field name="payment_term_id" widget="selection"/> <field name="payment_term_id" widget="selection"/>
<field name="renewal_type_id" widget="selection"/> <field name="renewal_type_id" widget="selection"/>
<field name="increase_type_id" widget="selection"/> <field name="increase_type_id" widget="selection"/>
@ -143,16 +142,16 @@
</page> </page>
<page name="signature" string="Signatures"> <page name="signature" string="Signatures">
<group> <group>
<group string="Partner">
<field name="partner_signed_date"/>
<field name="partner_signed_user_id" domain="[('parent_id', '=', partner_id)]"/>
</group>
<group string="Company"> <group string="Company">
<field name="company_signed_date"/> <field name="company_signed_date"/>
<field name="company_signed_user_id"/> <field name="company_signed_user_id"/>
<field name="signed_contract" filename="signed_contract_filename"/> <field name="signed_contract" filename="signed_contract_filename"/>
<field name="signed_contract_filename" invisible="1"/> <field name="signed_contract_filename" invisible="1"/>
</group> </group>
<group string="Customer">
<field name="customer_signed_date"/>
<field name="customer_signed_user_id" domain="[('parent_id', '=', customer_id)]"/>
</group>
</group> </group>
</page> </page>
<page name="products" string="Products/Services"> <page name="products" string="Products/Services">
@ -160,8 +159,20 @@
<field name="product_ids" nolabel="1"/> <field name="product_ids" nolabel="1"/>
</group> </group>
</page> </page>
<page name="costs" string="Costs">
<group string="Financial Details">
<page name="financials" string="Financials">
<group>
<group>
<field name="analytic_id"/>
</group>
<group></group>
</group>
<group string="Revenues and Costs">
<field name="analytic_line_ids"
readonly="1"
nolabel="1"/>
</group>
<!--
<group string="Financial Details>
<group string="Company"> <group string="Company">
<field name="total_company_mrc"/> <field name="total_company_mrc"/>
<field name="total_company_nrc"/> <field name="total_company_nrc"/>
@ -172,7 +183,7 @@
<field name="total_customer_mrc"/> <field name="total_customer_mrc"/>
<field name="total_customer_nrc"/> <field name="total_customer_nrc"/>
</group> </group>
</group>
</group> -->
</page> </page>
<page name="child_agreements" string="Child Agreements"> <page name="child_agreements" string="Child Agreements">
<field name="child_agreements_ids"> <field name="child_agreements_ids">
@ -235,7 +246,7 @@
<field name="name"/> <field name="name"/>
</strong><br/> </strong><br/>
<div class="o_kanban_record_subtitle text-muted"> <div class="o_kanban_record_subtitle text-muted">
<field name="customer_id" invisible="context.get('default_customer_id', False)"/>
<field name="partner_id" invisible="context.get('default_partner_id', False)"/>
<t t-if="record.start_date.raw_value and record.start_date.raw_value lt (new Date())" t-set="red">oe_kanban_text_red</t> <t t-if="record.start_date.raw_value and record.start_date.raw_value lt (new Date())" t-set="red">oe_kanban_text_red</t>
<div t-attf-class="#{red || ''}"> <div t-attf-class="#{red || ''}">
<i><field name="start_date"/></i> <i><field name="start_date"/></i>
@ -285,12 +296,40 @@
<filter name="filter_non_template" string="Non-Templates" domain="[('active','=',True),('is_template', '=', False)]"/> <filter name="filter_non_template" string="Non-Templates" domain="[('active','=',True),('is_template', '=', False)]"/>
<filter name="filter_inactive" string="Archived" domain="[('active','=',False)]"/> <filter name="filter_inactive" string="Archived" domain="[('active','=',False)]"/>
<filter name="filter_templates" string="Templates" domain="[('active','=',True),('is_template', '=', True)]"/> <filter name="filter_templates" string="Templates" domain="[('active','=',True),('is_template', '=', True)]"/>
<filter name="group_customer_id" string="customers" icon="terp-partner" context="{'group_by':'customer_id'}"/>
<filter name="group_partner_id" string="Partners" icon="terp-partner" context="{'group_by':'partner_id'}"/>
<filter name="group_status" string="Status" icon="terp-partner" context="{'group_by':'state'}"/> <filter name="group_status" string="Status" icon="terp-partner" context="{'group_by':'state'}"/>
</search> </search>
</field> </field>
</record> </record>
<!-- Agreement Reporting -->
<record id="agreement_graph_view" model="ir.ui.view">
<field name="name">agreement.graph</field>
<field name="model">agreement</field>
<field name="arch" type="xml">
<graph string="Agreements" type="bar">
<field name="stage_id" type="row"/>
</graph>
</field>
</record>
<record id="agreement_pivot_view" model="ir.ui.view">
<field name="name">agreement.pivot</field>
<field name="model">agreement</field>
<field name="arch" type="xml">
<pivot string="Agreements" display_quantity="true">
<field name="stage_id" type="row"/>
</pivot>
</field>
</record>
<record id="action_agreement_report_order" model="ir.actions.act_window">
<field name="name">Agreements</field>
<field name="res_model">agreement</field>
<field name="view_type">form</field>
<field name="view_mode">graph,pivot</field>
</record>
<!-- Adding a new filter to the order line search view --> <!-- Adding a new filter to the order line search view -->
<record id="order_lines_search_view" model="ir.ui.view"> <record id="order_lines_search_view" model="ir.ui.view">
<field name="name">Order Lines Search</field> <field name="name">Order Lines Search</field>

7
agreement/views/menu.xml

@ -67,6 +67,13 @@
parent="agreement_root" parent="agreement_root"
groups="agreement.group_agreement_manager"/> groups="agreement.group_agreement_manager"/>
<menuitem
name="Agreements"
id="agreement_agreement_reporting"
sequence="10"
parent="agreement_reporting"
action="action_agreement_report_order"/>
<!-- Configuration --> <!-- Configuration -->
<menuitem <menuitem
name="Configuration" name="Configuration"

Loading…
Cancel
Save