account_invoice_defer: issue11006 + issue11049 + issue11051

#048414
From changeset ec2938b
This commit is contained in:
Raimon Esteve 2022-02-07 12:05:31 +01:00
parent 7e4d8295a7
commit 2b08fd8b3f
4 changed files with 87 additions and 0 deletions

22
issue11006.diff Normal file
View File

@ -0,0 +1,22 @@
diff --git a/trytond/trytond/modules/account_invoice_defer/account.py b/trytond/trytond/modules/account_invoice_defer/account.py
index 09929e7..cd9a40f 100644
--- a/trytond/trytond/modules/account_invoice_defer/account.py
+++ b/trytond/trytond/modules/account_invoice_defer/account.py
@@ -164,7 +164,7 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
if journals:
self.journal, = journals
- @fields.depends('invoice_line', 'start_date')
+ @fields.depends('invoice_line', 'start_date', 'company')
def on_change_invoice_line(self):
pool = Pool()
Currency = pool.get('currency.currency')
@@ -172,7 +172,7 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
if not self.start_date:
self.start_date = self.invoice_line.invoice.invoice_date
invoice = self.invoice_line.invoice
- if invoice.currency != self.company.currency:
+ if self.company and invoice.currency != self.company.currency:
with Transaction().set_context(date=invoice.currency_date):
self.amount = Currency.compute(
invoice.currency, self.invoice_line.amount,

46
issue11049.diff Normal file
View File

@ -0,0 +1,46 @@
diff --git a/trytond/trytond/modules/account_invoice_defer/account.py b/trytond/trytond/modules/account_invoice_defer/account.py
index 09929e7..c58e120 100644
--- a/trytond/trytond/modules/account_invoice_defer/account.py
+++ b/trytond/trytond/modules/account_invoice_defer/account.py
@@ -4,6 +4,7 @@
from trytond.i18n import gettext
from trytond.model import ModelSQL, ModelView, Workflow, fields, Unique
from trytond.model.exceptions import AccessError
+from trytond.modules.account.exceptions import AccountMissing
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, If
from trytond.transaction import Transaction
@@ -357,9 +358,17 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
if invoice.type == 'out':
balance.account = configuration.get_multivalue(
'deferred_account_revenue', company=self.company.id)
+ if not balance.account:
+ raise AccountMissing(gettext(
+ 'account_invoice_defer.'
+ 'msg_missing_deferred_account_revenue'))
else:
balance.account = configuration.get_multivalue(
'deferred_account_expense', company=self.company.id)
+ if not balance.account:
+ raise AccountMissing(gettext(
+ 'account_invoice_defer.'
+ 'msg_missing_deferred_account_expense'))
balance.debit, balance.credit = income.credit, income.debit
if balance.account.party_required:
balance.party = invoice.party
diff --git a/trytond/trytond/modules/account_invoice_defer/message.xml b/trytond/trytond/modules/account_invoice_defer/message.xml
index cccdb09..28d1f88 100644
--- a/trytond/trytond/modules/account_invoice_defer/message.xml
+++ b/trytond/trytond/modules/account_invoice_defer/message.xml
@@ -12,5 +12,11 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_invoice_deferred_delete_draft">
<field name="text">You cannot delete invoice deferred "%(deferral)s" because it is not in "draft" state.</field>
</record>
+ <record model="ir.message" id="msg_missing_deferred_account_revenue">
+ <field name="text">There is no deferred account revenue configured.</field>
+ </record>
+ <record model="ir.message" id="msg_missing_deferred_account_expense">
+ <field name="text">There is no deferred account expense configured.</field>
+ </record>
</data>
</tryton>

15
issue11051.diff Normal file
View File

@ -0,0 +1,15 @@
diff --git a/trytond/trytond/modules/account_invoice_defer/account.py b/trytond/trytond/modules/account_invoice_defer/account.py
index 09929e7..96fd0d2 100644
--- a/trytond/trytond/modules/account_invoice_defer/account.py
+++ b/trytond/trytond/modules/account_invoice_defer/account.py
@@ -180,6 +180,10 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
else:
self.amount = self.invoice_line.amount
+ @classmethod
+ def default_company(cls):
+ return Transaction().context.get('company')
+
@classmethod
def default_state(cls):
return 'draft'

4
series
View File

@ -48,3 +48,7 @@ issue10161.diff # [sale] issue10161: Configuration of invoice_method and shipmen
issue8952.diff # [country] Use Tryton's CDN to download postal codes Remove on 6.4
issue11181.diff # [stock] Require unit price also for view location like for storage (only 6.0)
issue11051.diff # [account_invoice_defer] Add default company to invoice deferred (only 6.0)
issue11006.diff # [account_invoice_defer] Add company to on_change_invoice_line depends (only 6.0)
issue11049.diff # [account_invoice_defer] Raise user error message for account not configured (only 6.0)