Skip to content

Commit

Permalink
[FIX] account_tax_settlement
Browse files Browse the repository at this point in the history
Lo arreglamos con la menor intervención posible ya que en 16 tiene un gran refactor y cualquier mejora no va a sumar para adelante.
En resumen lo que hicimos fue depreciar (al igual que ya está en 16) la posibilidad de setear "new line" y que en realidad el saldo del asiento lo mande a una cuenta de contrapartida que solicite el asistente

closes #306

Signed-off-by: rov-adhoc <rov@adhoc.com.ar>
  • Loading branch information
jjscarafia committed Feb 16, 2024
1 parent 2b686d5 commit ab048e9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 38 deletions.
2 changes: 1 addition & 1 deletion account_tax_settlement/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'name': 'Tax Settlement',
'version': '15.0.1.3.0',
'version': '15.0.1.4.0',
'category': 'Accounting',
'sequence': 14,
'summary': '',
Expand Down
44 changes: 11 additions & 33 deletions account_tax_settlement/models/account_financial_html_report_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,18 @@ def create_tax_settlement_entry(self, journal):

lines_vals = journal._get_tax_settlement_entry_lines_vals(domain)

# agregamos otrs lineas ẗipo "new line"
new_lines = self.line_ids.search([
('id', 'child_of', self.line_ids.ids),
('settlement_type', 'in', ['new_line', 'new_line_negative'])])
balance = sum([x['debit'] - x['credit'] for x in lines_vals])
if not journal.company_id.currency_id.is_zero(balance):
account_id = self._context.get('counterpart_account_id')
if not account_id:
raise ValidationError('El asiento de liquidación no está balanceado. Debe configurar una cuenta de contrapartida en el asistente para poder realizar el mismo.')

# pasamos por contexto lo que viene adentro del contetxo como contexto
# porque asi lo interpreta _get_balance (en vez aparentemente
# report_move_lines_action busca dentro del contexto)
new_lines = new_lines.with_context(
new_lines._context.get('context'))
for new_line in new_lines:
account = self.env['account.account'].search([
('company_id', '=', journal.company_id.id),
('tag_ids', '=', new_line.settement_account_tag_id.id)],
limit=1)
if not account:
raise ValidationError(_(
'No account found with tag "%s" (id: %s) for company "%s".'
' Check report and accounts configuration.') % (
new_line.settement_account_tag_id.name,
new_line.settement_account_tag_id.id,
journal.company_id.name))
balance = sum(
[x['balance'] for x in new_line._get_balance(
{}, {}, self, field_names=['balance'])])
if journal.company_id.currency_id.is_zero(balance):
continue
balance = new_line.settlement_type == 'new_line' \
and balance or balance * -1.0
lines_vals.append({
'name': self.name,
# 'name': self.settlement_title,
'name': 'Contrapartida',
'debit': balance < 0.0 and -balance,
'credit': balance >= 0.0 and balance,
'account_id': account.id,
'account_id': account_id,
})

vals = journal._get_tax_settlement_entry_vals(lines_vals)
Expand All @@ -101,8 +79,8 @@ class AccountFinancialReportLine(models.Model):

settlement_type = fields.Selection([
('new_line', 'New Journal Item'),
('new_line_negative', 'New Journal Item (negative)'),
('revert', 'Revert Journal Item'),
('new_line_negative', 'DEPRECIADO'),
('revert', 'DEPRECIADO'),
], help="If you choose:\n"
"* New Journal Item: a new journal item with selected account will be "
"created\n"
Expand Down Expand Up @@ -139,4 +117,4 @@ def report_move_lines_action(self):
'res_model': 'account.move.line',
'view_mode': 'tree,form',
'domain': domain,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<group string="Tax Settlement" groups="base.group_no_one">
<field name="action_id" domain="[('binding_model_id.model', '=', 'account.financial.html.report.line')]"/>
<field name="settlement_type"/>
<field name="settement_account_tag_id" attrs="{'invisible': [('settlement_type', 'not in', ['new_line', 'new_line_negative'])], 'required': [('settlement_type', 'in', ['new_line', 'new_line_negative'])]}"/>
</group>
</group>
</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class AccountTaxSettlementWizard(models.TransientModel):
company_id = fields.Many2one(
'res.company',
)
account_id = fields.Many2one(
'account.account',
string='Cuenta contrapartida',
help='Cuenta contrapartida para asientos no balanceados. Luego puede revisar el asiento y modificarla de ser necesario.'
)
message = fields.Text(
)

Expand Down Expand Up @@ -83,7 +88,7 @@ def confirm(self):
self.ensure_one()
self = self.with_context(entry_date=self.date)
if self.report_id:
move = self.report_id.create_tax_settlement_entry(
move = self.report_id.with_context(counterpart_account_id=self.account_id.id).create_tax_settlement_entry(
self.settlement_journal_id)
else:
move = self.move_line_ids.create_tax_settlement_entry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<group>
<field name="date"/>
<field name="settlement_journal_id" attrs="{'invisible': [('select_journal', '=', False)], 'required': [('select_journal', '=', True)]}" domain="[('company_id', '=', company_id), ('type', '=', 'general')]"/>
<field name="account_id" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" attrs="{'invisible': [('select_journal', '=', False)]}"/>
</group>
<footer>
<button name="confirm" string="Confirm" type="object" class="oe_highlight"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
<field name="action_id" ref="action_recast_journal_entry"/>
</record>

<record id="account_reports.account_financial_report_net_profit0" model="account.financial.html.report.line">
<!-- <record id="account_reports.account_financial_report_net_profit0" model="account.financial.html.report.line">
<field name="settlement_type">new_line</field>
<field name="settement_account_tag_id" ref="l10n_ar_ux.tag_unaffected_earnings"/>
</record>
</record> -->

<record id="account_reports.account_financial_report_totalincome0" model="account.financial.html.report.line">
<field name="settlement_type">revert</field>
Expand Down

0 comments on commit ab048e9

Please sign in to comment.