Added compute writeoff

This commit is contained in:
oscar alvarez 2023-09-19 09:15:47 -05:00
parent fa6e70e46a
commit 94cde41a5c
5 changed files with 44 additions and 18 deletions

View File

@ -33,7 +33,6 @@ def register():
account.PrintTrialBalanceStart,
account.CashflowStatementContext,
account.PrintBalanceSheetCOLGAAPStart,
# account.BalanceSheetContextCol,
account.OpenChartAccountStart,
account.PrintIncomeStatementCOLGAAPStart,
account.PartyWithholdingStart,
@ -92,7 +91,6 @@ def register():
account.CashflowStatement,
invoice.MovesInvoicesReport,
audit.AuditReport,
# account.BalanceSheetDetail,
module='account_col', type_='report')
Pool.register(
move.MoveForceDraft,

View File

@ -470,9 +470,7 @@ class AuxiliaryBook(Report):
posted=data['posted'],
colgaap=data['colgaap']):
start_accounts = Account.browse(accounts)
print(start_accounts[0].balance, 'valida acceso')
end1 = timer()
delta1 = (end1 - start)
id2start_account = {}
for account in start_accounts:
id2start_account[account.id] = account
@ -1755,15 +1753,24 @@ class PartyWithholding(Report):
class AccountConfiguration(ModelSQL, ModelView):
__name__ = 'account.configuration'
equivalent_invoice_sec = fields.Many2One('ir.sequence',
'Equivalent Invoice', domain=[
('code', '=', 'account.invoice')
])
])
template_email_confirm = fields.Many2One(
'email.template', 'Template Email of Notification'
)
remove_tax = fields.Boolean('Remove Tax', help="Remove taxes on invoice if not exceeding the base")
account_debit_writeoff = fields.Many2One(
'account.account', 'Account Debit Writeoff', domain=[
('type', '!=', None),
]
)
account_credit_writeoff = fields.Many2One(
'account.account', 'Account Credit Writeoff', domain=[
('type', '!=', None),
]
)
class AuxiliaryPartyStart(ModelView):

View File

@ -8,7 +8,9 @@ from trytond.i18n import gettext
from trytond.model import ModelView, ModelSQL, fields, dualmethod
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, If, Bool
from trytond.wizard import Wizard, StateView, Button, StateReport, StateTransition
from trytond.wizard import (
Wizard, StateView, Button, StateReport, StateTransition
)
from trytond.transaction import Transaction
from trytond.modules.company import CompanyReport
from trytond.exceptions import UserError
@ -230,13 +232,28 @@ class Invoice(metaclass=PoolMeta):
)
elif inv.invoice_type == '91' and inv.original_invoice \
and inv.original_invoice.state == 'posted':
cls.reconcile_invoice(inv)
writeoff = None
pool = Pool()
Company = pool.get('company.company')
config = pool.get('account.configuration')(1)
company_id = Transaction().context.get('company')
company = Company(company_id)
# If currency is different we need activate writeoff
# Check for more info official account/move.py
# reconcile() method
if inv.currency != company.currency:
writeoff = WriteOff()
writeoff.journal = inv.journal
writeoff.debit_account = config.account_debit_writeoff
writeoff.credit_account = config.account_credit_writeoff
cls.reconcile_invoice(inv, writeoff=writeoff)
if inv.type == 'in':
cls.check_duplicated_reference(inv)
cls.check_advance(inv)
@classmethod
def reconcile_invoice(cls, invoice):
def reconcile_invoice(cls, invoice, writeoff=None):
pool = Pool()
MoveLine = pool.get('account.move.line')
origin = invoice.original_invoice
@ -247,14 +264,10 @@ class Invoice(metaclass=PoolMeta):
if inv.account == ml.account:
to_reconcile_lines.append(ml)
to_reconcile_lines.extend([l for l in origin.payment_lines])
MoveLine.reconcile(to_reconcile_lines)
MoveLine.reconcile(to_reconcile_lines, writeoff=writeoff)
@classmethod
def set_number(cls, invoices):
pool = Pool()
Authorization = pool.get('account.invoice.authorization')
config = pool.get('account.configuration')(1)
for invoice in invoices:
if not invoice.number and invoice.type == 'out' \
and invoice.authorization:
@ -427,13 +440,13 @@ class InvoiceLine(ModelSQL, ModelView):
return ['OR',
('type.revenue', '=', True),
('type.payable', '=', True)
]
]
elif type_ == 'in':
return ['OR',
('type.expense', '=', True),
('type.debt', '=', True),
('type.stock', '=', True),
]
]
@classmethod
def trigger_create(cls, records):
@ -727,7 +740,6 @@ class InvoiceUpdate(Wizard):
if self.start.party:
for line in invoice.lines:
line.party = self.start.party.id
print(type(invoice.lines), invoice.lines)
Line.write(list(invoice.lines), {'party': self.start.party.id})
Invoice.write([invoice], values)
@ -856,3 +868,8 @@ class InvoiceTax(ModelSQL):
if lines_:
lines = lines_
return lines
class WriteOff():
# Don't remove this class is neccesary for writeoff account move
pass

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.14
version=6.0.15
depends:
ir
res

View File

@ -9,6 +9,10 @@ this repository contains the full copyright notices and license terms. -->
<xpath expr="/form/field[@name='tax_rounding']" position="after">
<label name="remove_tax"/>
<field name="remove_tax"/>
<label name="account_debit_writeoff"/>
<field name="account_debit_writeoff"/>
<label name="account_credit_writeoff"/>
<field name="account_credit_writeoff"/>
<label name="template_email_confirm"/>
<field name="template_email_confirm"/>
</xpath>