Browse Source

[IMP] Contract: matching invoice view depending on contract type

[ADD] Contract: invoice partner
pull/207/head
Thomas Binsfeld 6 years ago
committed by sbejaoui
parent
commit
7683e5a736
  1. 2
      contract/__manifest__.py
  2. 15
      contract/migrations/12.0.3.0.0/post-migration.py
  3. 36
      contract/models/contract.py
  4. 2
      contract/views/contract.xml

2
contract/__manifest__.py

@ -9,7 +9,7 @@
{ {
'name': 'Recurring - Contracts Management', 'name': 'Recurring - Contracts Management',
'version': '12.0.2.0.1',
'version': '12.0.3.0.1',
'category': 'Contract Management', 'category': 'Contract Management',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': "OpenERP SA, " 'author': "OpenERP SA, "

15
contract/migrations/12.0.3.0.0/post-migration.py

@ -0,0 +1,15 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo import SUPERUSER_ID, api
_logger = logging.getLogger(__name__)
def migrate(cr, version):
_logger.info("Populate invoicing partner field on contracts")
env = api.Environment(cr, SUPERUSER_ID, {})
contracts = env["account.analytic.account"].search([])
contracts._inverse_partner_id()

36
contract/models/contract.py

@ -57,6 +57,22 @@ class AccountAnalyticAccount(models.Model):
string='Fiscal Position', string='Fiscal Position',
ondelete='restrict', ondelete='restrict',
) )
invoice_partner_id = fields.Many2one(
string="Invoicing contact",
comodel_name='res.partner',
ondelete='restrict',
)
partner_id = fields.Many2one(
comodel_name='res.partner',
inverse='_inverse_partner_id',
)
@api.multi
def _inverse_partner_id(self):
for rec in self:
if not rec.invoice_partner_id:
rec.invoice_partner_id = rec.partner_id.address_get(
['invoice'])['invoice']
@api.multi @api.multi
def _get_related_invoices(self): def _get_related_invoices(self):
@ -88,7 +104,14 @@ class AccountAnalyticAccount(models.Model):
@api.multi @api.multi
def action_show_invoices(self): def action_show_invoices(self):
self.ensure_one() self.ensure_one()
return {
tree_view_ref = 'account.invoice_supplier_tree' \
if self.contract_type == 'purchase' \
else 'account.invoice_tree_with_onboarding'
form_view_ref = 'account.invoice_supplier_form' \
if self.contract_type == 'purchase' else 'account.invoice_form'
tree_view = self.env.ref(tree_view_ref, raise_if_not_found=False)
form_view = self.env.ref(form_view_ref, raise_if_not_found=False)
action = {
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'name': 'Invoices', 'name': 'Invoices',
'res_model': 'account.invoice', 'res_model': 'account.invoice',
@ -96,6 +119,9 @@ class AccountAnalyticAccount(models.Model):
'view_mode': 'tree,kanban,form,calendar,pivot,graph,activity', 'view_mode': 'tree,kanban,form,calendar,pivot,graph,activity',
'domain': [('id', 'in', self._get_related_invoices().ids)], 'domain': [('id', 'in', self._get_related_invoices().ids)],
} }
if tree_view and form_view:
action['views'] = [(tree_view.id, 'tree'), (form_view.id, 'form')]
return action
@api.depends('recurring_invoice_line_ids.date_end') @api.depends('recurring_invoice_line_ids.date_end')
def _compute_date_end(self): def _compute_date_end(self):
@ -158,6 +184,12 @@ class AccountAnalyticAccount(models.Model):
def _onchange_partner_id(self): def _onchange_partner_id(self):
self.pricelist_id = self.partner_id.property_product_pricelist.id self.pricelist_id = self.partner_id.property_product_pricelist.id
self.fiscal_position_id = self.partner_id.property_account_position_id self.fiscal_position_id = self.partner_id.property_account_position_id
self.invoice_partner_id = self.partner_id.address_get(
['invoice'])['invoice']
return {'domain': {'invoice_partner_id': [
'|',
('id', 'parent_of', self.partner_id.id),
('id', 'child_of', self.partner_id.id)]}}
@api.constrains('partner_id', 'recurring_invoices') @api.constrains('partner_id', 'recurring_invoices')
def _check_partner_id_recurring_invoices(self): def _check_partner_id_recurring_invoices(self):
@ -215,7 +247,7 @@ class AccountAnalyticAccount(models.Model):
return { return {
'reference': self.code, 'reference': self.code,
'type': invoice_type, 'type': invoice_type,
'partner_id': self.partner_id.address_get(['invoice'])['invoice'],
'partner_id': self.invoice_partner_id.id,
'currency_id': currency.id, 'currency_id': currency.id,
'date_invoice': date_invoice, 'date_invoice': date_invoice,
'journal_id': journal.id, 'journal_id': journal.id,

2
contract/views/contract.xml

@ -90,6 +90,8 @@
<field name="currency_id" <field name="currency_id"
options="{'no_create': True}" options="{'no_create': True}"
groups="base.group_multi_currency"/> groups="base.group_multi_currency"/>
<field name="invoice_partner_id"
required="1"/>
</group> </group>
<group string="Legend (for the markers inside invoice lines description)" <group string="Legend (for the markers inside invoice lines description)"
name="group_legend"> name="group_legend">

Loading…
Cancel
Save