Browse Source

[IMP] - Add primary views for contract

[IMP] - don't use related filed for partner_id and pricelist_id
pull/207/head
sbejaoui 6 years ago
parent
commit
913405cdd2
  1. 30
      contract/models/abstract_contract_line.py
  2. 36
      contract/models/contract_line.py
  3. 2
      contract/models/contract_template.py
  4. 16
      contract/models/contract_template_line.py
  5. 2
      contract/tests/test_contract.py
  6. 2
      contract/views/abstract_contract_line.xml
  7. 231
      contract/views/contract.xml
  8. 130
      contract/views/contract_line.xml

30
contract/models/abstract_contract_line.py

@ -79,13 +79,6 @@ class AccountAbstractAnalyticContractLine(models.AbstractModel):
help="Repeat every (Days/Week/Month/Year)",
required=True,
)
partner_id = fields.Many2one(
comodel_name="res.partner", string="Partner (always False)"
)
pricelist_id = fields.Many2one(
comodel_name='product.pricelist', string='Pricelist'
)
recurring_next_date = fields.Date(string='Date of Next Invoice')
is_canceled = fields.Boolean(string="Canceled", default=False)
@ -109,14 +102,21 @@ class AccountAbstractAnalyticContractLine(models.AbstractModel):
default='monthly',
string='Termination Notice type',
)
contract_id = fields.Many2one(
string='Contract',
comodel_name='account.abstract.analytic.contract',
required=True,
ondelete='cascade',
oldname='analytic_account_id',
)
@api.depends(
'automatic_price',
'specific_price',
'product_id',
'quantity',
'pricelist_id',
'partner_id',
'contract_id.pricelist_id',
'contract_id.partner_id',
)
def _compute_price_unit(self):
"""Get the specific price if no auto-price, and the price obtained
@ -128,8 +128,8 @@ class AccountAbstractAnalyticContractLine(models.AbstractModel):
quantity=line.env.context.get(
'contract_line_qty', line.quantity
),
pricelist=line.pricelist_id.id,
partner=line.partner_id.id,
pricelist=line.contract_id.pricelist_id.id,
partner=line.contract_id.partner_id.id,
date=line.env.context.get('old_date', fields.Date.today()),
)
line.price_unit = product.price
@ -150,8 +150,8 @@ class AccountAbstractAnalyticContractLine(models.AbstractModel):
subtotal = line.quantity * line.price_unit
discount = line.discount / 100
subtotal *= 1 - discount
if line.pricelist_id:
cur = line.pricelist_id.currency_id
if line.contract_id.pricelist_id:
cur = line.contract_id.pricelist_id.currency_id
line.price_subtotal = cur.round(subtotal)
else:
line.price_subtotal = subtotal
@ -183,14 +183,14 @@ class AccountAbstractAnalyticContractLine(models.AbstractModel):
vals['uom_id'] = self.product_id.uom_id
date = self.recurring_next_date or fields.Date.today()
partner = self.partner_id or self.env.user.partner_id
partner = self.contract_id.partner_id or self.env.user.partner_id
product = self.product_id.with_context(
lang=partner.lang,
partner=partner.id,
quantity=self.quantity,
date=date,
pricelist=self.pricelist_id.id,
pricelist=self.contract_id.pricelist_id.id,
uom=self.uom_id.id,
)

36
contract/models/contract_line.py

@ -26,20 +26,6 @@ class AccountAnalyticInvoiceLine(models.Model):
create_invoice_visibility = fields.Boolean(
compute='_compute_create_invoice_visibility'
)
partner_id = fields.Many2one(
comodel_name="res.partner",
string="Partner (always False)",
related='contract_id.partner_id',
store=True,
readonly=True,
)
pricelist_id = fields.Many2one(
comodel_name='product.pricelist',
string='Pricelist',
related='contract_id.pricelist_id',
store=True,
readonly=True,
)
successor_contract_line_id = fields.Many2one(
comodel_name='account.analytic.invoice.line',
string="Successor Contract Line",
@ -793,3 +779,25 @@ class AccountAnalyticInvoiceLine(models.Model):
domain = self._contract_line_to_renew_domain()
to_renew = self.search(domain)
to_renew.renew()
@api.model
def fields_view_get(
self, view_id=None, view_type='form', toolbar=False, submenu=False
):
default_contract_type = self.env.context.get('default_contract_type')
if view_type == 'tree' and default_contract_type == 'purchase':
view_id = self.env.ref(
'contract.account_analytic_invoice_line_purchase_view_tree'
).id
if view_type == 'form':
if default_contract_type == 'purchase':
view_id = self.env.ref(
'contract.account_analytic_invoice_line_purchase_view_form'
).id
elif default_contract_type == 'sale':
view_id = self.env.ref(
'contract.account_analytic_invoice_line_sale_view_form'
).id
return super(AccountAnalyticInvoiceLine, self).fields_view_get(
view_id, view_type, toolbar, submenu
)

2
contract/models/contract_template.py

@ -16,7 +16,7 @@ class AccountAnalyticContract(models.Model):
recurring_invoice_line_ids = fields.One2many(
comodel_name='account.analytic.contract.line',
inverse_name='contract_template_id',
inverse_name='contract_id',
copy=True,
string='Invoice Lines',
)

16
contract/models/contract_template_line.py

@ -15,24 +15,10 @@ class AccountAnalyticContractLine(models.Model):
_description = 'Contract Lines'
_order = "sequence,id"
contract_template_id = fields.Many2one(
contract_id = fields.Many2one(
string='Contract',
comodel_name='account.analytic.contract',
required=True,
ondelete='cascade',
oldname='analytic_account_id',
)
partner_id = fields.Many2one(
comodel_name="res.partner",
string="Partner (always False)",
related='contract_template_id.partner_id',
store=True,
readonly=True,
)
pricelist_id = fields.Many2one(
comodel_name='product.pricelist',
string='Pricelist',
related='contract_template_id.pricelist_id',
store=True,
readonly=True,
)

2
contract/tests/test_contract.py

@ -111,7 +111,7 @@ class TestContract(TestContractBase):
del vals['contract_id']
del vals['date_start']
del vals['date_end']
vals['contract_template_id'] = self.template.id
vals['contract_id'] = self.template.id
vals.update(overrides)
return self.env['account.analytic.contract.line'].create(vals)

2
contract/views/abstract_contract_line.xml

@ -18,7 +18,7 @@
<field name="specific_price" invisible="1"/>
<field colspan="2" name="price_unit"
attrs="{'readonly': [('automatic_price', '=', True)]}"/>
<field colspan="2" name="discount"/>
<field colspan="2" name="discount" groups="base.group_no_one"/>
</group>
<group col="4">
<field colspan="2" name="is_auto_renew"/>

231
contract/views/contract.xml

@ -5,140 +5,110 @@
model="ir.ui.view">
<field name="name">Contract form</field>
<field name="model">account.analytic.account</field>
<field name="inherit_id"
ref="analytic.view_account_analytic_account_form"/>
<field name="mode">primary</field>
<field name="priority" eval="9999"/>
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="attrs">{'required': [('recurring_invoices',
'=', True)]}
</attribute>
</field>
<xpath expr="//div[@name='button_box']/.." position="before">
<form>
<header>
<button name="action_contract_send" type="object"
string="Send by Email" groups="base.group_user"/>
</header>
</xpath>
<xpath expr='//field[@name="code"]' position='before'>
<field name="contract_type" invisible="1" required="1"/>
</xpath>
<group name="main" position="after">
<separator string="Recurring Invoices"
attrs="{'invisible': [('recurring_invoices','!=',True)]}"
/>
<div>
<field name="recurring_invoices" class="oe_inline"/>
<field name="create_invoice_visibility" invisible="1"/>
<label for="recurring_invoices"/>
<button name="action_contract_send"
type="object"
string="Send by Email"
groups="base.group_user"/>
<button name="recurring_create_invoice"
type="object"
attrs="{'invisible': ['|', ('recurring_invoices', '!=', True), ('create_invoice_visibility', '=', False)]}"
attrs="{'invisible': [('create_invoice_visibility', '=', False)]}"
string="Create invoices"
class="oe_link"
groups="base.group_no_one"
/>
<button name="contract.act_recurring_invoices"
type="action"
attrs="{'invisible': [('recurring_invoices','!=',True)]}"
string="⇒ Show recurring invoices"
class="oe_link"
/>
</div>
<group col="4"
attrs="{'invisible': [('recurring_invoices','!=',True)]}">
<field name="contract_template_id" colspan="4"
domain="['|', ('contract_type', '=', contract_type), ('contract_type', '=', False)]"
context="{'default_contract_type': contract_type}"/>
<field name="journal_id"
domain="[('type', '=', contract_type),('company_id', '=', company_id)]"
attrs="{'required': [('recurring_invoices', '=', True)]}"
/>
<field name="pricelist_id"/>
<field name="recurring_next_date"/>
<field name="date_end"/>
<field name="company_id"
groups="base.group_multi_company"/>
</group>
<label for="recurring_invoice_line_ids"
attrs="{'invisible': [('recurring_invoices','=',False)]}"
/>
<div attrs="{'invisible': [('recurring_invoices','=',False)]}">
<field name="recurring_invoice_line_ids">
<tree decoration-muted="is_canceled" decoration-info="create_invoice_visibility and not is_canceled">
<field name="sequence" widget="handle"/>
<field name="product_id"/>
<field name="name"/>
<field name="quantity"/>
<field name="uom_id"/>
<field name="automatic_price"/>
<field name="price_unit"
attrs="{'readonly': [('automatic_price', '=', True)]}"/>
<field name="specific_price" invisible="1"/>
<field name="discount" groups="base.group_no_one"/>
<field name="price_subtotal"/>
<field name="recurring_interval" invisible="1"/>
<field name="recurring_rule_type" invisible="1"/>
<field name="recurring_invoicing_type"
invisible="1"/>
<field name="date_start" required="1"/>
groups="base.group_no_one"/>
</header>
<sheet string="Contract">
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" type="object"
name="toggle_active" icon="fa-archive">
<field name="active" widget="boolean_button"
options="{&quot;terminology&quot;: &quot;archive&quot;}"/>
</button>
<button name="contract.act_recurring_invoices"
type="action"
string="Invoices"
icon="fa-list"
class="oe_stat_button"/>
</div>
<div class="oe_title">
<label for="name" string="Contract Name"
class="oe_edit_only"/>
<h3>
<field name="name" class="oe_inline"
placeholder="e.g. Contract XYZ"/>
</h3>
</div>
<group name="main">
<group>
<field name="partner_id" required="1"/>
</group>
<group>
<field name="contract_template_id"
domain="['|', ('contract_type', '=', contract_type), ('contract_type', '=', False)]"
context="{'default_contract_type': contract_type}"/>
<field name="contract_type" invisible="1"
required="1"/>
</group>
</group>
<group name="recurring_invoices">
<group>
<field name="journal_id" required="1"/>
<field name="recurring_next_date"/>
</group>
<group>
<field name="pricelist_id"/>
<field name="date_end"/>
<field name="recurring_next_date" required="1" attrs="{'invisible': [('create_invoice_visibility', '=', False)]}"/>
</group>
</group>
<notebook>
<page name="recurring_invoice_line"
string="Recurring Invoices">
<field name="recurring_invoice_line_ids" context="{'default_contract_type': contract_type}"/>
</page>
<page name="info" string="Other Information">
<div invisible="1">
<field name="recurring_invoices"
class="oe_inline"/>
<label for="recurring_invoices"/>
</div>
<field name="create_invoice_visibility"
invisible="1"/>
<field name="is_plan_successor_allowed" invisible="1"/>
<field name="is_stop_plan_successor_allowed" invisible="1"/>
<field name="is_stop_allowed" invisible="1"/>
<field name="is_cancel_allowed" invisible="1"/>
<field name="is_un_cancel_allowed" invisible="1"/>
<field name="is_auto_renew" invisible="1"/>
<field name="is_canceled" invisible="1"/>
<button name="action_plan_successor"
string="Plan Start"
type="object"
icon="fa-calendar text-success"
attrs="{'invisible': [('is_plan_successor_allowed', '=', False)]}"/>
<button name="action_stop_plan_successor"
string="Stop Plan Successor"
type="object"
icon="fa-pause text-muted"
attrs="{'invisible': [('is_stop_plan_successor_allowed', '=', False)]}"/>
<button name="action_stop"
string="Stop"
type="object"
icon="fa-stop text-danger"
attrs="{'invisible': [('is_stop_allowed', '=', False)]}"/>
<button name="cancel"
string="Cancel"
type="object"
icon="fa-ban text-danger"
attrs="{'invisible': [('is_cancel_allowed', '=', False)]}"/>
<button name="action_uncancel"
string="Un-cancel"
type="object"
icon="fa-ban text-success"
attrs="{'invisible': [('is_un_cancel_allowed', '=', False)]}"/>
<button name="renew"
string="Renew"
type="object"
icon="fa-fast-forward text-success"
groups="base.group_no_one"
attrs="{'invisible': [('is_auto_renew', '=', False)]}"/>
</tree>
</field>
<group>
<field name="code"/>
<field name="group_id"/>
<field name="company_id"
options="{'no_create': True}"
groups="base.group_multi_company"/>
<field name="currency_id"
options="{'no_create': True}"
groups="base.group_multi_currency"/>
</group>
<group string="Legend (for the markers inside invoice lines description)"
name="group_legend">
<p colspan="2"><strong>#START#</strong>: Start
date
of the
invoiced period
</p>
<p colspan="2"><strong>#END#</strong>: End date
of
the
invoiced period
</p>
</group>
</page>
</notebook>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids"
widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
<group string="Legend (for the markers inside invoice lines description)"
name="group_legend"
attrs="{'invisible': [('recurring_invoices','!=',True)]}">
<p colspan="2"><strong>#START#</strong>: Start date of the
invoiced period
</p>
<p colspan="2"><strong>#END#</strong>: End date of the
invoiced period
</p>
</group>
</group>
</form>
</field>
</record>
@ -160,9 +130,6 @@
<field name="journal_id" position="attributes">
<attribute name="domain">[('type', '=', 'sale'),('company_id', '=', company_id)]</attribute>
</field>
<field name="product_id" position="attributes">
<attribute name="domain">[('sale_ok', '=', True)]</attribute>
</field>
</field>
</record>
@ -184,14 +151,6 @@
<field name="journal_id" position="attributes">
<attribute name="domain">[('type', '=', 'purchase'),('company_id', '=', company_id)]</attribute>
</field>
<field name="product_id" position="attributes">
<attribute name="domain">[('purchase_ok', '=', True)]
</attribute>
</field>
<xpath expr="//field[@name='recurring_invoice_line_ids']/tree/field[@name='automatic_price']"
position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
</field>
</record>

130
contract/views/contract_line.xml

@ -20,10 +20,11 @@
<group>
<field name="create_invoice_visibility" invisible="1"/>
<field name="date_start" required="1"/>
<field name="recurring_next_date" attrs="{'invisible': [('create_invoice_visibility', '=', False)]}"/>
<field name="recurring_next_date"/>
</group>
<group>
<field name="date_end" attrs="{'required': [('is_auto_renew', '=', True)]}"/>
<field name="date_end"
attrs="{'required': [('is_auto_renew', '=', True)]}"/>
</group>
<group>
<field name="predecessor_contract_line_id"/>
@ -35,4 +36,129 @@
</field>
</record>
<record id="account_analytic_invoice_line_sale_view_form"
model="ir.ui.view">
<field name="name">account.analytic.invoice.line.sale.form</field>
<field name="model">account.analytic.invoice.line</field>
<field name="inherit_id"
ref="account_analytic_invoice_line_view_form"/>
<field name="mode">primary</field>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="product_id" position="attributes">
<attribute name="domain">[('sale_ok', '=', True)]</attribute>
</field>
</field>
</record>
<record id="account_analytic_invoice_line_purchase_view_form"
model="ir.ui.view">
<field name="name">account.analytic.invoice.line.purchase.form</field>
<field name="model">account.analytic.invoice.line</field>
<field name="inherit_id"
ref="account_analytic_invoice_line_view_form"/>
<field name="mode">primary</field>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="product_id" position="attributes">
<attribute name="domain">[('purchase_ok', '=', True)]
</attribute>
</field>
<xpath expr="//field[@name='automatic_price']"
position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
</field>
</record>
<record id="account_analytic_invoice_line_view_tree" model="ir.ui.view">
<field name="name">account.analytic.invoice.line.tree</field>
<field name="model">account.analytic.invoice.line</field>
<field name="arch" type="xml">
<tree decoration-muted="is_canceled"
decoration-info="create_invoice_visibility and not is_canceled">
<field name="sequence" widget="handle"/>
<field name="product_id"/>
<field name="name"/>
<field name="quantity"/>
<field name="uom_id"/>
<field name="automatic_price"/>
<field name="price_unit"
attrs="{'readonly': [('automatic_price', '=', True)]}"/>
<field name="specific_price"
invisible="1"/>
<field name="discount"
groups="base.group_no_one"/>
<field name="price_subtotal"/>
<field name="recurring_interval"
invisible="1"/>
<field name="recurring_rule_type"
invisible="1"/>
<field name="recurring_invoicing_type"
invisible="1"/>
<field name="date_start" required="1"/>
<field name="date_end"/>
<field name="recurring_next_date"
required="1"
attrs="{'invisible': [('create_invoice_visibility', '=', False)]}"/>
<field name="create_invoice_visibility"
invisible="1"/>
<field name="is_plan_successor_allowed"
invisible="1"/>
<field name="is_stop_plan_successor_allowed"
invisible="1"/>
<field name="is_stop_allowed"
invisible="1"/>
<field name="is_cancel_allowed"
invisible="1"/>
<field name="is_un_cancel_allowed"
invisible="1"/>
<field name="is_auto_renew" invisible="1"/>
<field name="is_canceled" invisible="1"/>
<button name="action_plan_successor"
string="Plan Start" type="object"
icon="fa-calendar text-success"
attrs="{'invisible': [('is_plan_successor_allowed', '=', False)]}"/>
<button name="action_stop_plan_successor"
string="Stop Plan Successor"
type="object"
icon="fa-pause text-muted"
attrs="{'invisible': [('is_stop_plan_successor_allowed', '=', False)]}"/>
<button name="action_stop" string="Stop"
type="object"
icon="fa-stop text-danger"
attrs="{'invisible': [('is_stop_allowed', '=', False)]}"/>
<button name="cancel" string="Cancel"
type="object"
icon="fa-ban text-danger"
attrs="{'invisible': [('is_cancel_allowed', '=', False)]}"/>
<button name="action_uncancel"
string="Un-cancel" type="object"
icon="fa-ban text-success"
attrs="{'invisible': [('is_un_cancel_allowed', '=', False)]}"/>
<button name="renew" string="Renew"
type="object"
icon="fa-fast-forward text-success"
groups="base.group_no_one"
attrs="{'invisible': [('is_auto_renew', '=', False)]}"/>
</tree>
</field>
</record>
<record id="account_analytic_invoice_line_purchase_view_tree"
model="ir.ui.view">
<field name="name">account.analytic.invoice.line.purchase.tree</field>
<field name="model">account.analytic.invoice.line</field>
<field name="mode">primary</field>
<field name="priority" eval="20"/>
<field name="inherit_id"
ref="account_analytic_invoice_line_view_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='automatic_price']"
position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save