From 81ebb003a1718e6c2d48e1e6d00183563b65afae Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Tue, 12 Nov 2019 12:20:08 +0100 Subject: [PATCH] In case the invoice line has analytic accounts and customer invoice, copy analytic lines to move lines issue5909 #039256 --- __init__.py | 7 +++++-- invoice.py | 31 +++++++++++++++++++++++++++++++ tryton.cfg | 2 ++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 invoice.py diff --git a/__init__.py b/__init__.py index 97f820a..d87424c 100644 --- a/__init__.py +++ b/__init__.py @@ -1,10 +1,9 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. from trytond.pool import Pool - from . import account from . import analytic - +from . import invoice def register(): Pool.register( @@ -19,6 +18,10 @@ def register(): account.MoveLine, analytic.OpenChartAccountStart, module='analytic_line_state', type_='model') + Pool.register( + invoice.InvoiceLine, + depends=['account_invoice'], + module='analytic_line_state', type_='model') Pool.register( analytic.OpenChartAccount, module='analytic_line_state', type_='wizard') diff --git a/invoice.py b/invoice.py new file mode 100644 index 0000000..087e176 --- /dev/null +++ b/invoice.py @@ -0,0 +1,31 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from trytond.model import fields +from trytond.pool import PoolMeta, Pool +from trytond.pyson import Eval, If + +__all__ = ['InvoiceLine'] + + +class InvoiceLine(metaclass=PoolMeta): + __name__ = 'account.invoice.line' + + def get_move_lines(self): + lines = super(InvoiceLine, self).get_move_lines() + if self.invoice and self.invoice.type: + type_ = self.invoice.type + else: + type_ = self.invoice_type + # analytic_invoice add analytic accounts when is supplier invoice (in) + # See issue5909 + # In case the invoice line has analytic accounts and customer invoice, + # copy analytic lines to move lines. + if type_ == 'out' and self.analytic_accounts: + date = self.invoice.accounting_date or self.invoice.invoice_date + for line in lines: + analytic_lines = [] + for entry in self.analytic_accounts: + analytic_lines.extend( + entry.get_analytic_lines(line, date)) + line.analytic_lines = analytic_lines + return lines diff --git a/tryton.cfg b/tryton.cfg index 9d24df2..5a933d3 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -4,6 +4,8 @@ depends: account analytic_account company +extras_depend: + account_invoice xml: account.xml analytic.xml