From 3c5c33886cfa9e2c840db9849fc5527a1edbfef8 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 23 Nov 2018 12:07:45 +0100 Subject: [PATCH] [IMP] - Add primary views for contract [IMP] - don't use related filed for partner_id and pricelist_id --- contract/models/abstract_contract_line.py | 30 +-- contract/models/contract_line.py | 36 ++-- contract/models/contract_template.py | 2 +- contract/models/contract_template_line.py | 16 +- contract/tests/test_contract.py | 2 +- contract/views/abstract_contract_line.xml | 2 +- contract/views/contract.xml | 231 +++++++++------------- contract/views/contract_line.xml | 130 +++++++++++- 8 files changed, 264 insertions(+), 185 deletions(-) diff --git a/contract/models/abstract_contract_line.py b/contract/models/abstract_contract_line.py index d3c6b2d4..e4438305 100644 --- a/contract/models/abstract_contract_line.py +++ b/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, ) diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index d6369456..13e1b159 100644 --- a/contract/models/contract_line.py +++ b/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 + ) diff --git a/contract/models/contract_template.py b/contract/models/contract_template.py index 48064f2c..5bf8af08 100644 --- a/contract/models/contract_template.py +++ b/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', ) diff --git a/contract/models/contract_template_line.py b/contract/models/contract_template_line.py index abeca107..208187e3 100644 --- a/contract/models/contract_template_line.py +++ b/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, - ) diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index b3b1eb72..6a7c626c 100644 --- a/contract/tests/test_contract.py +++ b/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) diff --git a/contract/views/abstract_contract_line.xml b/contract/views/abstract_contract_line.xml index 7626e416..0823b29c 100644 --- a/contract/views/abstract_contract_line.xml +++ b/contract/views/abstract_contract_line.xml @@ -18,7 +18,7 @@ - + diff --git a/contract/views/contract.xml b/contract/views/contract.xml index f1d4370c..00f5d222 100644 --- a/contract/views/contract.xml +++ b/contract/views/contract.xml @@ -5,140 +5,110 @@ model="ir.ui.view"> Contract form account.analytic.account - - primary - - - {'required': [('recurring_invoices', - '=', True)]} - - - +
-
- - - - - - -
- - -
- - - - - - - - -