From acc880888e8eb53f377664f4610efa2dc66065cf Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Wed, 16 Jan 2019 09:32:48 +0100 Subject: [PATCH] [ADD] Contract: fiscal position [ADD] Contract: new contributor [REF] Contract: indexes --- contract/models/abstract_contract.py | 5 ++++- contract/models/contract.py | 12 +++++++++++- contract/readme/CONTRIBUTORS.rst | 2 ++ contract/views/contract.xml | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/contract/models/abstract_contract.py b/contract/models/abstract_contract.py index 1f69daa2..1c6292f9 100644 --- a/contract/models/abstract_contract.py +++ b/contract/models/abstract_contract.py @@ -19,7 +19,8 @@ class AbstractAccountAnalyticContract(models.AbstractModel): name = fields.Char(required=True) # Needed for avoiding errors on several inherited behaviors partner_id = fields.Many2one( - comodel_name="res.partner", string="Partner (always False)" + comodel_name="res.partner", string="Partner (always False)", + index=True, ) pricelist_id = fields.Many2one( comodel_name='product.pricelist', string='Pricelist' @@ -27,6 +28,7 @@ class AbstractAccountAnalyticContract(models.AbstractModel): contract_type = fields.Selection( selection=[('sale', 'Customer'), ('purchase', 'Supplier')], default='sale', + index=True, ) journal_id = fields.Many2one( @@ -35,6 +37,7 @@ class AbstractAccountAnalyticContract(models.AbstractModel): default=lambda s: s._default_journal(), domain="[('type', '=', contract_type)," "('company_id', '=', company_id)]", + index=True, ) company_id = fields.Many2one( 'res.company', diff --git a/contract/models/contract.py b/contract/models/contract.py index d83b4ac3..27627da4 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -48,9 +48,15 @@ class AccountAnalyticAccount(models.Model): compute='_compute_date_end', string='Date End', store=True ) payment_term_id = fields.Many2one( - comodel_name='account.payment.term', string='Payment Terms' + comodel_name='account.payment.term', string='Payment Terms', + index=True, ) invoice_count = fields.Integer(compute="_compute_invoice_count") + fiscal_position_id = fields.Many2one( + comodel_name='account.fiscal.position', + string='Fiscal Position', + ondelete='restrict', + ) @api.multi def _get_related_invoices(self): @@ -151,6 +157,7 @@ class AccountAnalyticAccount(models.Model): @api.onchange('partner_id') def _onchange_partner_id(self): self.pricelist_id = self.partner_id.property_product_pricelist.id + self.fiscal_position_id = self.partner_id.property_account_position_id @api.constrains('partner_id', 'recurring_invoices') def _check_partner_id_recurring_invoices(self): @@ -216,6 +223,7 @@ class AccountAnalyticAccount(models.Model): 'company_id': self.company_id.id, 'user_id': self.partner_id.user_id.id, 'payment_term_id': self.payment_term_id.id, + 'fiscal_position_id': self.fiscal_position_id.id, } @api.multi @@ -279,8 +287,10 @@ class AccountAnalyticAccount(models.Model): def _finalize_invoice_creation(self, invoices): for invoice in invoices: payment_term = invoice.payment_term_id + fiscal_position = invoice.fiscal_position_id invoice._onchange_partner_id() invoice.payment_term_id = payment_term + invoice.fiscal_position_id = fiscal_position invoices.compute_taxes() @api.model diff --git a/contract/readme/CONTRIBUTORS.rst b/contract/readme/CONTRIBUTORS.rst index 820de990..4a73f3d0 100644 --- a/contract/readme/CONTRIBUTORS.rst +++ b/contract/readme/CONTRIBUTORS.rst @@ -5,3 +5,5 @@ * Vicent Cubells * Miquel Raïch * Souheil Bejaoui +* Thomas Binsfeld + diff --git a/contract/views/contract.xml b/contract/views/contract.xml index 1f337a9d..9c019fe7 100644 --- a/contract/views/contract.xml +++ b/contract/views/contract.xml @@ -53,6 +53,7 @@ context="{'default_contract_type': contract_type}"/> +