From face64191d1dd5709e4cde42260bf4d702c9e2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 29 Sep 2012 15:34:34 +0200 Subject: [PATCH] Rationalize accounting moves and lines issue2056 review503006 --- __init__.py | 1 + account.py | 11 +++++++++-- invoice.py | 18 +++++++++--------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/__init__.py b/__init__.py index 7f66c28122..4636280ed2 100644 --- a/__init__.py +++ b/__init__.py @@ -25,6 +25,7 @@ def register(): Party, FiscalYear, Period, + Move, Reconciliation, module='account_invoice', type_='model') Pool.register( diff --git a/account.py b/account.py index 3bc26f570b..d6d74c956f 100644 --- a/account.py +++ b/account.py @@ -4,7 +4,7 @@ from trytond.model import fields from trytond.pyson import Eval from trytond.pool import Pool, PoolMeta -__all__ = ['FiscalYear', 'Period', 'Reconciliation'] +__all__ = ['FiscalYear', 'Period', 'Move', 'Reconciliation'] __metaclass__ = PoolMeta @@ -213,13 +213,20 @@ class Period: super(Period, cls).write(periods, vals) +class Move: + __name__ = 'account.move' + + @classmethod + def _get_origin(cls): + return super(Move, cls)._get_origin() + ['account.invoice'] + + class Reconciliation: __name__ = 'account.move.reconciliation' @classmethod def create(cls, values): Invoice = Pool().get('account.invoice') - reconciliation = super(Reconciliation, cls).create(values) move_ids = set(l.move.id for l in reconciliation.lines) invoices = Invoice.search([ diff --git a/invoice.py b/invoice.py index 4dc5e362c5..3035406bc8 100644 --- a/invoice.py +++ b/invoice.py @@ -797,8 +797,7 @@ class Invoice(Workflow, ModelSQL, ModelView): res['credit'] = Decimal('0.0') res['account'] = self.account.id res['maturity_date'] = date - res['reference'] = self.reference - res['name'] = self.number + res['description'] = self.description res['party'] = self.party.id return res @@ -843,6 +842,7 @@ class Invoice(Workflow, ModelSQL, ModelView): 'journal': self.journal.id, 'period': period_id, 'date': accounting_date, + 'origin': str(self), 'lines': [('create', x) for x in move_lines], }) self.write([self], { @@ -1044,7 +1044,7 @@ class Invoice(Workflow, ModelSQL, ModelView): if self.type in ('out_invoice', 'in_credit_note'): lines.append({ - 'name': description, + 'description': description, 'account': self.account.id, 'party': self.party.id, 'debit': Decimal('0.0'), @@ -1053,7 +1053,7 @@ class Invoice(Workflow, ModelSQL, ModelView): 'second_currency': second_currency, }) lines.append({ - 'name': description, + 'description': description, 'account': journal.debit_account.id, 'party': self.party.id, 'debit': amount, @@ -1067,7 +1067,7 @@ class Invoice(Workflow, ModelSQL, ModelView): self.raise_user_error('missing_debit_account') else: lines.append({ - 'name': description, + 'description': description, 'account': self.account.id, 'party': self.party.id, 'debit': amount, @@ -1076,7 +1076,7 @@ class Invoice(Workflow, ModelSQL, ModelView): 'second_currency': second_currency, }) lines.append({ - 'name': description, + 'description': description, 'account': journal.credit_account.id, 'party': self.party.id, 'debit': Decimal('0.0'), @@ -1737,7 +1737,7 @@ class InvoiceLine(ModelSQL, ModelView): res = {} if self.type != 'line': return [] - res['name'] = self.description + res['description'] = self.description if self.invoice.currency != self.invoice.company.currency: with Transaction().set_context(date=self.invoice.currency_date): amount = Currency.compute(self.invoice.currency, @@ -1985,7 +1985,7 @@ class InvoiceTax(ModelSQL, ModelView): res = {} if not self.amount: return [] - res['name'] = self.description + res['description'] = self.description if self.invoice.currency != self.invoice.company.currency: with Transaction().set_context(date=self.invoice.currency_date): amount = Currency.compute(self.invoice.currency, self.amount, @@ -2131,7 +2131,7 @@ class PayInvoiceStart(ModelView): currency = fields.Many2One('currency.currency', 'Currency', required=True) currency_digits = fields.Integer('Currency Digits', readonly=True, on_change_with=['currency']) - description = fields.Char('Description', size=None, required=True) + description = fields.Char('Description', size=None) journal = fields.Many2One('account.journal', 'Journal', required=True, domain=[('type', '=', 'cash')]) date = fields.Date('Date', required=True)