get amount on line as net-value (even if invoice is gross-mode)
This commit is contained in:
parent
a5bf930e55
commit
214cbb086f
4 changed files with 85 additions and 3 deletions
36
mixin.py
36
mixin.py
|
@ -10,6 +10,7 @@ from trytond.exceptions import UserError
|
|||
from trytond.i18n import gettext
|
||||
from trytond.tools import cached_property
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.modules.product import round_price
|
||||
|
||||
|
||||
|
@ -160,6 +161,41 @@ class EdocumentMixin(object):
|
|||
taxname=tax.rec_name))
|
||||
return tax.unece_code
|
||||
|
||||
def get_line_amount(self, line):
|
||||
""" get amount of current invoice-line,
|
||||
depends on modegross of invoice, set used-modegross to 'net'
|
||||
|
||||
Args:
|
||||
line (record): model account.invoice.line
|
||||
"""
|
||||
if line.modegross == 'net':
|
||||
return line.amount
|
||||
elif line.modegross == 'gross':
|
||||
# get net-amount
|
||||
# copy from account_invoice/invoice.py:2416-2434
|
||||
currency = (
|
||||
line.invoice.currency
|
||||
if line.invoice else line.currency)
|
||||
|
||||
amount = (Decimal(str(line.quantity or 0)) * (
|
||||
line.unit_price or Decimal(0)))
|
||||
invoice_type = (
|
||||
line.invoice.type
|
||||
if line.invoice else line.invoice_type)
|
||||
|
||||
if (invoice_type == 'in'
|
||||
and line.taxes_deductible_rate is not None
|
||||
and line.taxes_deductible_rate != 1):
|
||||
with Transaction().set_context(_deductible_rate=1):
|
||||
tax_amount = sum(
|
||||
t['amount'] for t in line._get_taxes().values())
|
||||
non_deductible_amount = (
|
||||
tax_amount * (1 - line.taxes_deductible_rate))
|
||||
amount += non_deductible_amount
|
||||
if currency:
|
||||
return currency.round(amount)
|
||||
return amount
|
||||
|
||||
def get_tax_unece_code(self, tax):
|
||||
while tax:
|
||||
if tax.unece_code:
|
||||
|
|
|
@ -85,7 +85,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<ram:SpecifiedLineTradeSettlement>
|
||||
${TradeTax(this.invoice_line_tax(line))}
|
||||
<ram:SpecifiedTradeSettlementLineMonetarySummation>
|
||||
<ram:LineTotalAmount py:attrs="{'currencyID': this.invoice.currency.code}">${line.amount}</ram:LineTotalAmount>
|
||||
<ram:LineTotalAmount py:attrs="{'currencyID': this.invoice.currency.code}">${this.get_line_amount(line)}</ram:LineTotalAmount>
|
||||
</ram:SpecifiedTradeSettlementLineMonetarySummation>
|
||||
</ram:SpecifiedLineTradeSettlement>
|
||||
</ram:IncludedSupplyChainTradeLineItem>
|
||||
|
|
|
@ -7,7 +7,8 @@ from lxml import etree
|
|||
import os
|
||||
from decimal import Decimal
|
||||
from datetime import date
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import (
|
||||
ModuleTestCase, with_transaction, activate_module)
|
||||
from trytond.pool import Pool
|
||||
from trytond.modules.company.tests import create_company, set_company
|
||||
from trytond.modules.account.tests import create_chart, get_fiscalyear
|
||||
|
@ -42,6 +43,14 @@ class EdocTestCase(ModuleTestCase):
|
|||
'Test e-rechnung module'
|
||||
module = 'edocument_xrechnung'
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
activate_module([
|
||||
'edocument_uncefact', 'party', 'bank',
|
||||
'account_invoice', 'sale_point_invoice',
|
||||
'product_grossprice'], 'en')
|
||||
|
||||
def prep_fiscalyear(self, company1):
|
||||
""" prepare fiscal year, sequences...
|
||||
"""
|
||||
|
@ -84,7 +93,7 @@ class EdocTestCase(ModuleTestCase):
|
|||
'number': 'DE02300209000106531065'}])]}])
|
||||
return company
|
||||
|
||||
def prep_invoice(self, credit_note=False):
|
||||
def prep_invoice(self, credit_note=False, modegross='net'):
|
||||
""" add invoice
|
||||
"""
|
||||
pool = Pool()
|
||||
|
@ -130,6 +139,7 @@ class EdocTestCase(ModuleTestCase):
|
|||
|
||||
to_create_invoice = [{
|
||||
'type': 'out',
|
||||
'modegross': modegross,
|
||||
'description': 'description of invoice',
|
||||
'comment': 'note line 1\nnote line 2',
|
||||
'invoice_date': date(2024, 7, 1),
|
||||
|
@ -149,6 +159,11 @@ class EdocTestCase(ModuleTestCase):
|
|||
'currency': currency1.id,
|
||||
}])],
|
||||
}]
|
||||
|
||||
if modegross == 'gross':
|
||||
to_create_invoice[0]['lines'][0][1][0]['unit_gross_price'] = (
|
||||
Decimal('50.0') * Decimal('1.2'))
|
||||
|
||||
inv_lst, = Invoice.create(to_create_invoice)
|
||||
inv_lst.on_change_lines()
|
||||
inv_lst.save()
|
||||
|
@ -233,6 +248,34 @@ class EdocTestCase(ModuleTestCase):
|
|||
{'identifiers': [('delete', [party.identifiers[0].id])]}]
|
||||
)
|
||||
|
||||
@with_transaction()
|
||||
def test_xrechn_export_facturx_gross(self):
|
||||
""" run export - factur-x, modegross='gross'
|
||||
"""
|
||||
pool = Pool()
|
||||
Template = pool.get('edocument.facturxext.invoice')
|
||||
|
||||
company = self.prep_company()
|
||||
with set_company(company):
|
||||
create_chart(company=company, tax=True)
|
||||
self.prep_fiscalyear(company)
|
||||
invoice = self.prep_invoice(modegross='gross')
|
||||
|
||||
template = Template(invoice)
|
||||
|
||||
schema_file = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'Factur-X_1.07.2_EXTENDED',
|
||||
'Factur-X_1.07.2_EXTENDED.xsd')
|
||||
|
||||
invoice_string = template.render('Factur-X-1.07.2-extended')
|
||||
with open('gross_invoice_string.xml', 'wb') as fhdl:
|
||||
fhdl.write(invoice_string)
|
||||
|
||||
invoice_xml = etree.fromstring(invoice_string)
|
||||
schema = etree.XMLSchema(etree.parse(schema_file))
|
||||
schema.assertValid(invoice_xml)
|
||||
|
||||
@with_transaction()
|
||||
def test_xrechn_export_facturx(self):
|
||||
""" run export - factur-x
|
||||
|
|
|
@ -5,6 +5,9 @@ depends:
|
|||
party
|
||||
bank
|
||||
account_invoice
|
||||
extras_depend:
|
||||
sale_point_invoice
|
||||
product_grossprice
|
||||
xml:
|
||||
message.xml
|
||||
configuration.xml
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue