Update way of amount total is calculated. And add a warning when set to draft and invoice it this invoice are in a SII book sended

This commit is contained in:
Bernat Brunet Torruella 2018-06-19 16:20:35 +02:00
parent 1835f06e50
commit 833f77ca33
2 changed files with 25 additions and 2 deletions

View file

@ -54,8 +54,14 @@ class BaseTrytonInvoiceMapper(Model):
def get_invoice_total(self, invoice):
taxes = self.total_invoice_taxes(invoice)
total = 0
taxes_used = {}
for tax in taxes:
total += (tax.company_base + tax.company_amount)
base = tax.company_base
parent = tax.tax.parent if tax.tax.parent else tax.tax
if parent.id in taxes_used.keys() and base == taxes_used[parent.id]:
continue
total += (base + tax.company_amount)
taxes_used[parent.id] = base
return total
counterpart_id_type = attrgetter('party.sii_identifier_type')
@ -99,7 +105,7 @@ class BaseTrytonInvoiceMapper(Model):
invoice_tax.tax.tax_used and
not invoice_tax.tax.recargo_equivalencia)]
def taxes(self, invoice):
def total_invoice_taxes(self, invoice):
return [invoice_tax for invoice_tax in invoice.taxes if (
invoice_tax.tax.invoice_used and
not invoice_tax.tax.recargo_equivalencia)]

View file

@ -61,6 +61,12 @@ class Invoice:
'sii_received_key', 'sii_issued_key', 'sii_subjected_key',
'sii_excemption_key', 'sii_intracomunity_key']
cls._check_modify_exclude += sii_fields
cls._error_messages.update({
'invoices_sii': 'The next invoices are related with SII books:\n'
'%s.\n\nIf yuo edit them take care if you need to update '
'again to SII',
})
cls._buttons.update({
'reset_sii_keys': {
'invisible': Bool(Eval('sii_state', None)),
@ -197,6 +203,17 @@ class Invoice:
if to_write:
cls.write(*to_write)
@classmethod
def draft(cls, invoices):
super(Invoice, cls).draft(invoices)
invoices_sii = ''
for invoice in invoices:
if invoice.sii_state:
invoices_sii += '\n%s: %s' % (invoice.number, invoice.sii_state)
if invoices_sii:
warning_name = 'invoices_sii_report'
cls.raise_user_warning(warning_name, 'invoices_sii', invoices_sii)
class Sale:
__metaclass__ = PoolMeta