mirror of
https://gitlab.com/datalifeit/trytond-aeat_sii
synced 2023-12-13 20:30:37 +01:00
Inverse amounts for credit notes
This commit is contained in:
parent
1792e91d59
commit
e06b647eb4
1 changed files with 19 additions and 5 deletions
|
@ -19,6 +19,20 @@ __all__ = [
|
|||
_logger = getLogger(__name__)
|
||||
|
||||
|
||||
def _amount_getter(field_name):
|
||||
# In tryton 3.4 credit note amounts are positive
|
||||
# They must be negative before being informed to SII
|
||||
# This code should not be merged into higher tryton series
|
||||
|
||||
def is_credit_note(invoice):
|
||||
return (invoice.type in {'in_credit_note', 'out_credit_note'})
|
||||
|
||||
def amount_getter(self, invoice):
|
||||
val = attrgetter(field_name)(invoice)
|
||||
return val if val is None or not is_credit_note(invoice) else -val
|
||||
return amount_getter
|
||||
|
||||
|
||||
class BaseTrytonInvoiceMapper(Model):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -36,11 +50,11 @@ class BaseTrytonInvoiceMapper(Model):
|
|||
counterpart_nif = attrgetter('party.vat_number')
|
||||
counterpart_id_type = attrgetter('party.sii_identifier_type')
|
||||
counterpart_id = counterpart_nif
|
||||
untaxed_amount = attrgetter('untaxed_amount')
|
||||
total_amount = attrgetter('total_amount')
|
||||
untaxed_amount = _amount_getter('untaxed_amount')
|
||||
total_amount = _amount_getter('total_amount')
|
||||
tax_rate = attrgetter('tax.rate')
|
||||
tax_base = attrgetter('base')
|
||||
tax_amount = attrgetter('amount')
|
||||
tax_base = _amount_getter('base')
|
||||
tax_amount = _amount_getter('amount')
|
||||
|
||||
def counterpart_name(self, invoice):
|
||||
return tools.unaccent(invoice.party.name)
|
||||
|
@ -125,6 +139,6 @@ class RecievedTrytonInvoiceMapper(mapping.RecievedInvoiceMapper,
|
|||
serial_number = attrgetter('reference')
|
||||
specialkey_or_trascendence = attrgetter('sii_received_key')
|
||||
move_date = attrgetter('move.date')
|
||||
deductible_amount = attrgetter('tax_amount') # most of the times
|
||||
deductible_amount = _amount_getter('tax_amount') # most of the times
|
||||
tax_reagyp_rate = BaseTrytonInvoiceMapper.tax_rate
|
||||
tax_reagyp_amount = BaseTrytonInvoiceMapper.tax_amount
|
||||
|
|
Loading…
Reference in a new issue