From 97828a5e6b1def7aa8a5c418b9bb63c6ea5e7ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 24 Mar 2019 18:00:01 +0100 Subject: [PATCH] Merge account kind and account type issue4990 review68401002 --- CHANGELOG | 2 ++ __init__.py | 2 ++ account.py | 47 +++++++++++++++++++++++++++++- account.xml | 18 ++++++++++++ minimal_chart.xml | 38 ++++++++++++++++++++++++ minimal_chart_bg.xml | 38 ++++++++++++++++++++++++ minimal_chart_ca.xml | 38 ++++++++++++++++++++++++ minimal_chart_de.xml | 38 ++++++++++++++++++++++++ minimal_chart_en.xml | 38 ++++++++++++++++++++++++ minimal_chart_es.xml | 38 ++++++++++++++++++++++++ minimal_chart_fr.xml | 38 ++++++++++++++++++++++++ minimal_chart_nl.xml | 38 ++++++++++++++++++++++++ minimal_chart_pt.xml | 38 ++++++++++++++++++++++++ minimal_chart_ru.xml | 38 ++++++++++++++++++++++++ minimal_chart_sl.xml | 38 ++++++++++++++++++++++++ sale.py | 5 ++-- tests/scenario_advance_payment.rst | 16 ++-------- tests/tools.py | 16 ++++++++++ tryton.cfg | 12 ++++++++ view/account_type_form.xml | 9 ++++++ 20 files changed, 529 insertions(+), 16 deletions(-) create mode 100644 account.xml create mode 100644 minimal_chart.xml create mode 100644 minimal_chart_bg.xml create mode 100644 minimal_chart_ca.xml create mode 100644 minimal_chart_de.xml create mode 100644 minimal_chart_en.xml create mode 100644 minimal_chart_es.xml create mode 100644 minimal_chart_fr.xml create mode 100644 minimal_chart_nl.xml create mode 100644 minimal_chart_pt.xml create mode 100644 minimal_chart_ru.xml create mode 100644 minimal_chart_sl.xml create mode 100644 view/account_type_form.xml diff --git a/CHANGELOG b/CHANGELOG index 1e534508a0..fd87e1e943 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add unearned revenue on account type + Version 5.0.0 - 2018-10-01 * Bug fixes (see mercurial logs for details) * Remove support for Python 2.7 diff --git a/__init__.py b/__init__.py index d564301704..34afd60dc7 100644 --- a/__init__.py +++ b/__init__.py @@ -15,6 +15,8 @@ def register(): sale.AdvancePaymentCondition, sale.Sale, sale.SaleLine, + account.AccountTypeTemplate, + account.AccountType, account.Invoice, account.InvoiceLine, stock.ShipmentOut, diff --git a/account.py b/account.py index 346ef9f0de..b4d6536bb8 100644 --- a/account.py +++ b/account.py @@ -1,9 +1,47 @@ # 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 Pool, PoolMeta +from trytond.pyson import If, Eval, Bool -__all__ = ['Invoice', 'InvoiceLine'] + +def AccountTypeMixin(template=False): + + class Mixin: + unearned_revenue = fields.Boolean( + "Unearned Revenue", + domain=[ + If(Eval('statement') != 'balance', + ('unearned_revenue', '=', False), ()), + ], + states={ + 'invisible': ((Eval('statement') != 'balance') + | Eval('assets', True)), + }, + depends=['statement', 'assets']) + if not template: + for fname in dir(Mixin): + field = getattr(Mixin, fname) + if not isinstance(field, fields.Field): + continue + field.states['readonly'] = ( + Bool(Eval('template', -1)) & ~Eval('template_override', False)) + return Mixin + + +class AccountTypeTemplate(AccountTypeMixin(template=True), metaclass=PoolMeta): + __name__ = 'account.account.type.template' + + def _get_type_value(self, type=None): + values = super()._get_type_value(type=type) + if not type or type.unearned_revenue != self.unearned_revenue: + values['unearned_revenue'] = self.unearned_revenue + return values + + +class AccountType(AccountTypeMixin(), metaclass=PoolMeta): + __name__ = 'account.account.type' class Invoice(metaclass=PoolMeta): @@ -23,6 +61,13 @@ class Invoice(metaclass=PoolMeta): class InvoiceLine(metaclass=PoolMeta): __name__ = 'account.invoice.line' + @classmethod + def _account_domain(cls, type_): + domain = super()._account_domain(type_) + if type_ == 'out': + domain.append(('type.unearned_revenue', '=', True)) + return domain + @classmethod def _get_origin(cls): return (super(InvoiceLine, cls)._get_origin() diff --git a/account.xml b/account.xml new file mode 100644 index 0000000000..fce0b91fe3 --- /dev/null +++ b/account.xml @@ -0,0 +1,18 @@ + + + + + + account.account.type.template + + account_type_form + + + + account.account.type + + account_type_form + + + diff --git a/minimal_chart.xml b/minimal_chart.xml new file mode 100644 index 0000000000..af96040b3f --- /dev/null +++ b/minimal_chart.xml @@ -0,0 +1,38 @@ + + + + + + Unearned Revenue + Неотработен доход + Ingressos no consumits + Nicht verdiente Einnahmen + Ingresos no ganados + Produits constatés d'avance + Onverdiende inkomsten + Receita não recebida + Нетрудовые доходы + Nezasluženi prihodki + + balance + + + + + + Advance Payment + Авансово плащане + Pagament avançat + Vorauszahlung + Pago por adelantado + Acompte + Vooruitbetaling + Pagamento adiantado + Предоплата + Plačilo vnaprej + + + + + diff --git a/minimal_chart_bg.xml b/minimal_chart_bg.xml new file mode 100644 index 0000000000..b753dc6108 --- /dev/null +++ b/minimal_chart_bg.xml @@ -0,0 +1,38 @@ + + + + + + + Неотработен доход + + + + + + + + + + balance + + + + + + + Авансово плащане + + + + + + + + + + + + + diff --git a/minimal_chart_ca.xml b/minimal_chart_ca.xml new file mode 100644 index 0000000000..9899eaaebe --- /dev/null +++ b/minimal_chart_ca.xml @@ -0,0 +1,38 @@ + + + + + + + + Ingressos no consumits + + + + + + + + + balance + + + + + + + + Pagament avançat + + + + + + + + + + + + diff --git a/minimal_chart_de.xml b/minimal_chart_de.xml new file mode 100644 index 0000000000..7ff1c1fc52 --- /dev/null +++ b/minimal_chart_de.xml @@ -0,0 +1,38 @@ + + + + + + + + + Nicht verdiente Einnahmen + + + + + + + + balance + + + + + + + + + Vorauszahlung + + + + + + + + + + + diff --git a/minimal_chart_en.xml b/minimal_chart_en.xml new file mode 100644 index 0000000000..bd25b98bf8 --- /dev/null +++ b/minimal_chart_en.xml @@ -0,0 +1,38 @@ + + + + + + Unearned Revenue + + + + + + + + + + + balance + + + + + + Advance Payment + + + + + + + + + + + + + + diff --git a/minimal_chart_es.xml b/minimal_chart_es.xml new file mode 100644 index 0000000000..6cd9d63543 --- /dev/null +++ b/minimal_chart_es.xml @@ -0,0 +1,38 @@ + + + + + + + + + + Ingresos no ganados + + + + + + + balance + + + + + + + + + + Pago por adelantado + + + + + + + + + + diff --git a/minimal_chart_fr.xml b/minimal_chart_fr.xml new file mode 100644 index 0000000000..383eb1b955 --- /dev/null +++ b/minimal_chart_fr.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + Produits constatés d'avance + + + + + + balance + + + + + + + + + + + Acompte + + + + + + + + + diff --git a/minimal_chart_nl.xml b/minimal_chart_nl.xml new file mode 100644 index 0000000000..9c2b8c3af7 --- /dev/null +++ b/minimal_chart_nl.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + Onverdiende inkomsten + + + + + balance + + + + + + + + + + + + Vooruitbetaling + + + + + + + + diff --git a/minimal_chart_pt.xml b/minimal_chart_pt.xml new file mode 100644 index 0000000000..6b392ef8d4 --- /dev/null +++ b/minimal_chart_pt.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + Receita não recebida + + + + balance + + + + + + + + + + + + + Pagamento adiantado + + + + + + + diff --git a/minimal_chart_ru.xml b/minimal_chart_ru.xml new file mode 100644 index 0000000000..80e1a42bbf --- /dev/null +++ b/minimal_chart_ru.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + Нетрудовые доходы + + + balance + + + + + + + + + + + + + + Предоплата + + + + + + diff --git a/minimal_chart_sl.xml b/minimal_chart_sl.xml new file mode 100644 index 0000000000..acadf95f1f --- /dev/null +++ b/minimal_chart_sl.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + Nezasluženi prihodki + + balance + + + + + + + + + + + + + + + Plačilo vnaprej + + + + + diff --git a/sale.py b/sale.py index 66eb0e0f52..c4552b3fe6 100644 --- a/sale.py +++ b/sale.py @@ -61,7 +61,7 @@ class AdvancePaymentTermLine(ModelView, ModelSQL, CompanyMultiValueMixin): account = fields.MultiValue( fields.Many2One('account.account', "Account", required=True, domain=[ - ('kind', '=', 'revenue'), + ('type.unearned_revenue', '=', True), ], help="Used for the line of advance payment invoice.")) accounts = fields.One2Many( @@ -132,6 +132,7 @@ class AdvancePaymentTermLineAccount(ModelSQL, CompanyValueMixin): account = fields.Many2One( 'account.account', "Account", required=True, domain=[ + ('type.unearned_revenue', '=', True), ('company', '=', Eval('company', -1)), ], depends=['company']) @@ -163,7 +164,7 @@ class AdvancePaymentCondition(ModelSQL, ModelView): account = fields.Many2One( 'account.account', "Account", required=True, domain=[ - ('kind', '=', 'revenue'), + ('type.unearned_revenue', '=', True), ('company', '=', Eval('sale_company')), ], states=_states, diff --git a/tests/scenario_advance_payment.rst b/tests/scenario_advance_payment.rst index 3f8a15dbe5..e57e5dc41a 100644 --- a/tests/scenario_advance_payment.rst +++ b/tests/scenario_advance_payment.rst @@ -16,7 +16,7 @@ Imports:: >>> from trytond.modules.account_invoice.tests.tools import \ ... set_fiscalyear_invoice_sequences, create_payment_term >>> from trytond.modules.sale_advance_payment.tests.tools import \ - ... create_advance_payment_term + ... create_advance_payment_term, add_advance_payment_accounts >>> today = datetime.date.today() Activate sale_advance_payment:: @@ -40,21 +40,11 @@ Create fiscal years:: Create chart of accounts:: >>> _ = create_chart(company) - >>> accounts = get_accounts(company) + >>> accounts = add_advance_payment_accounts(get_accounts(company)) >>> revenue = accounts['revenue'] >>> payable = accounts['payable'] >>> cash = accounts['cash'] - - >>> Account = Model.get('account.account') - >>> advance_payment_account = Account( - ... name='Advance Payment', - ... type=payable.type, - ... kind='revenue', - ... company=company, - ... party_required=True, - ... reconcile=True, - ... ) - >>> advance_payment_account.save() + >>> advance_payment_account = accounts['advance_payment'] >>> Journal = Model.get('account.journal') >>> PaymentMethod = Model.get('account.invoice.payment.method') diff --git a/tests/tools.py b/tests/tools.py index 1b185db62e..d19e74970a 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -4,6 +4,8 @@ from datetime import timedelta from proteus import Model +from trytond.modules.company.tests.tools import get_company + def create_advance_payment_term( name, formula, account, block_supply=False, block_shipping=False, @@ -21,3 +23,17 @@ def create_advance_payment_term( line.formula = formula line.invoice_delay = timedelta(days=delay) return advance_payment_term + + +def add_advance_payment_accounts(accounts, company=None, config=None): + "Add advance payment to accounts" + Account = Model.get('account.account', config=config) + + if not company: + company = get_company() + + accounts['advance_payment'], = Account.find([ + ('type.unearned_revenue', '=', True), + ('company', '=', company.id), + ], limit=1) + return accounts diff --git a/tryton.cfg b/tryton.cfg index 236a51c82a..ebdeca4d92 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,6 +1,7 @@ [tryton] version=5.1.0 depends: + account account_invoice ir res @@ -9,4 +10,15 @@ extras_depend: sale_supply xml: sale.xml + account.xml + minimal_chart_bg.xml + minimal_chart_ca.xml + minimal_chart_de.xml + minimal_chart_en.xml + minimal_chart_es.xml + minimal_chart_fr.xml + minimal_chart_nl.xml + minimal_chart_pt.xml + minimal_chart_ru.xml + minimal_chart_sl.xml message.xml diff --git a/view/account_type_form.xml b/view/account_type_form.xml new file mode 100644 index 0000000000..aab4506835 --- /dev/null +++ b/view/account_type_form.xml @@ -0,0 +1,9 @@ + + + + + +