Skip to content

Commit

Permalink
[MIG] l10n_ar_account_withholding: Migration to 16.0
Browse files Browse the repository at this point in the history
closes #663

Related: ingadhoc/odoo-argentina-ee#169
Related: ingadhoc/account-payment#339
Related: ingadhoc/argentina-sale#116
Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
  • Loading branch information
ica-adhoc authored and jjscarafia committed Jan 2, 2023
1 parent b82b6ca commit 37fef50
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 77 deletions.
4 changes: 2 additions & 2 deletions l10n_ar_account_withholding/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'external_dependencies': {
'python': ['pyafipws'],
},
'installable': False,
'installable': True,
'name': 'Automatic Argentinian Withholdings on Payments',
'version': "15.0.1.2.0",
'version': "16.0.1.0.0",
}
59 changes: 8 additions & 51 deletions l10n_ar_account_withholding/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, fields, api
from odoo import models


class AccountMove(models.Model):
Expand All @@ -14,53 +14,10 @@ def _get_tax_factor(self):
tax_factor = 1.0 / 1.21
return tax_factor

def _recompute_tax_lines(self, recompute_tax_base_amount=False, tax_rep_lines_to_recompute=None):
"""
Hacemos esto para disponer de fecha de factura y cia para calcular
impuesto con código python (por ej. para ARBA).
Aparentemente no se puede cambiar el contexto a cosas que se llaman
desde un onchange (ver https://github.com/odoo/odoo/issues/7472)
entonces usamos este artilugio
"""
invoice = self.reversed_entry_id or self
invoice_date = invoice.invoice_date or fields.Date.context_today(self)
self = self.with_context(invoice_date=invoice_date)
return super(AccountMove, self)._recompute_tax_lines(recompute_tax_base_amount=recompute_tax_base_amount, tax_rep_lines_to_recompute=tax_rep_lines_to_recompute)

@api.onchange('invoice_date', 'reversed_entry_id')
def _onchange_tax_date(self):
""" Si cambia la fecha o cambiamos el refund asociado tenemos que recalcular los impuestos """
self._onchange_invoice_date()
if self.invoice_line_ids.mapped('tax_ids').filtered(lambda x: x.amount_type == 'partner_tax'):
# si no recomputamos no se guarda el cambio en las lineas
self.line_ids._onchange_price_subtotal()
self._recompute_dynamic_lines(recompute_all_taxes=True)


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

def _get_price_total_and_subtotal(
self, price_unit=None, quantity=None, discount=None, currency=None,
product=None, partner=None, taxes=None, move_type=None):
invoice = self.move_id.reversed_entry_id or self.move_id
invoice_date = invoice.invoice_date or fields.Date.context_today(self)
self = self.with_context(invoice_date=invoice_date)
return super(AccountMoveLine, self)._get_price_total_and_subtotal(
price_unit=price_unit, quantity=quantity, discount=discount, currency=currency,
product=product, partner=partner, taxes=taxes, move_type=move_type)

def _get_fields_onchange_balance(
self, quantity=None, discount=None, amount_currency=None, move_type=None,
currency=None, taxes=None, price_subtotal=None, force_computation=False):
invoice = self.move_id.reversed_entry_id or self.move_id
invoice_date = invoice.invoice_date or fields.Date.context_today(self)
self = self.with_context(invoice_date=invoice_date)
return super(AccountMoveLine, self)._get_fields_onchange_balance(
quantity=quantity, discount=discount, amount_currency=amount_currency, move_type=move_type,
currency=currency, taxes=taxes, price_subtotal=price_subtotal, force_computation=force_computation)

# TODO faltaria heredar al momento de creacion porque se llama a _get_price_total_and_subtotal_model y no estamos
# teniendo en cuenta la fecha que podria pasarse en vals_list
# @api.model_create_multi
# def create(self, vals_list):
def _compute_tax_totals(self):
""" Mandamos en contexto el invoice_date para cauclo de impuesto con partner aliquot"""
invoices = self.filtered(lambda x: x.is_invoice(include_receipts=True))
for invoice in invoices:
invoice = invoice.with_context(invoice_date=invoice.invoice_date)
super(AccountMove, invoice)._compute_tax_totals()
super(AccountMove, self - invoices)._compute_tax_totals()
11 changes: 5 additions & 6 deletions l10n_ar_account_withholding/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from odoo import models, fields
from odoo import models


class AccountMoveLine(models.Model):

_inherit = 'account.move.line'

def compute_l10n_latam_prices_and_taxes(self):
""" When computing the prices and taxes compute we pass the invoice date
in order to properly compute the perception/retention rates """
def _compute_all_tax(self):
""" Mandamos en contexto el invoice_date para calculo de impuesto con partner aliquot"""
for line in self:
invoice_date = line.move_id.invoice_date or fields.Date.context_today(self)
super(AccountMoveLine, line.with_context(invoice_date=invoice_date)).compute_l10n_latam_prices_and_taxes()
line = line.with_context(invoice_date=line.move_id.invoice_date)
super(AccountMoveLine, line)._compute_all_tax()
6 changes: 3 additions & 3 deletions l10n_ar_account_withholding/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ def get_partner_alicuot(self, partner, date):
return alicuot

def _compute_amount(
self, base_amount, price_unit, quantity=1.0, product=None,
partner=None):
self, base_amount, price_unit, quantity=1.0, product=None, partner=None, fixed_multiplicator=1):
if self.amount_type == 'partner_tax':
date = self._context.get('invoice_date', fields.Date.context_today(self))
partner = partner and partner.sudo()
return base_amount * self.sudo().get_partner_alicuota_percepcion(partner, date)
else:
return super(AccountTax, self)._compute_amount(
base_amount, price_unit, quantity, product, partner)
base_amount, price_unit, quantity=quantity, product=product,
partner=partner, fixed_multiplicator=fixed_multiplicator)
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@
<field name="name">res.partner.arba_alicuot.form.inherit</field>
<field name="inherit_id" ref="view_res_partner_arba_alicuot_form"/>
<field name="model">res.partner.arba_alicuot</field>
<field name="groups_id" eval="[(4, ref('partner_tax_withholding_amount_type'))]"/>
<field name="arch" type="xml">
<field name="alicuota_retencion" position="after">
<field name="withholding_amount_type" required="True"/>
</field>
<!-- TODO mejorar esto, por ahora solo lo hacemos visible con este grupo ya que este grupo solo lo estamos usando en realidad para API, deberiamos ver de hacerlo de otra manera -->
<notebook>
<page string="API">
<page string="API" groups="l10n_ar_account_withholding.l10n_apartner_tax_withholding_amount_type">
<group>
<field name="api_codigo_articulo_retencion"/>
<field name="api_articulo_inciso_calculo_retencion"/>
Expand Down
21 changes: 10 additions & 11 deletions l10n_ar_ux/models/account_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ class AccountAccount(models.Model):
def set_non_monetary_tag(self, company):
""" Set <Non Monetary> tag to the corresponding accounts taking into account the account type """
non_monetary_tag = self.env.ref('l10n_ar_ux.no_monetaria_tag')
xml_ids = [
'account.data_account_type_non_current_assets',
'account.data_account_type_fixed_assets',
'account.data_account_type_other_income',
'account.data_account_type_revenue',
'account.data_account_type_expenses',
'account.data_account_type_depreciation',
'account.data_account_type_equity',
'account.data_account_type_direct_costs',
account_types = [
'asset_non_current',
'asset_fixed',
'income',
'income_other',
'expense',
'expense_depreciation',
'equity',
'expense_direct_cost',
]
account_types = [self.env.ref(xml_id).id for xml_id in xml_ids]
accounts = self.search([('user_type_id', 'in', account_types), ('company_id', 'in', company.ids)])
accounts = self.search([('account_type', 'in', account_types), ('company_id', 'in', company.ids)])
if accounts:
accounts.write({'tag_ids': [(4, non_monetary_tag.id)]})
4 changes: 2 additions & 2 deletions l10n_ar_ux/reports/report_payment_group.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
</tr>
</thead>
<tbody>
<t t-foreach="o.env['account.move.line'].search([('partner_id', '=', o.partner_id.commercial_partner_id.id), ('account_id.internal_type', '=', o.partner_type=='customer' and 'receivable' or 'payable'), ('reconciled', '=', False), ('account_id.deprecated', '=', False), ('move_id.state', '=', 'posted'), ('company_id', '=', o.company_id.id)])" t-as="line">
<t t-foreach="o.env['account.move.line'].search([('partner_id', '=', o.partner_id.commercial_partner_id.id), ('account_id.account_type', '=', o.partner_type=='customer' and 'asset_receivable' or 'liability_payable'), ('reconciled', '=', False), ('account_id.deprecated', '=', False), ('move_id.state', '=', 'posted'), ('company_id', '=', o.company_id.id)])" t-as="line">
<tr>
<td><span t-field='line.move_id.display_name'/></td>
<td class="text-center">
Expand All @@ -194,7 +194,7 @@
<tr>
<td colspan="3"><strong><span>Total Pendiente</span></strong></td>
<td class="text-right">
<strong><span class="text-nowrap" t-out="sum(o.env['account.move.line'].search([('partner_id', '=', o.partner_id.commercial_partner_id.id), ('account_id.internal_type', '=', o.partner_type=='customer' and 'receivable' or 'payable'), ('reconciled', '=', False), ('account_id.deprecated', '=', False), ('move_id.state', '=', 'posted'), ('company_id', '=', o.company_id.id)]).mapped('amount_residual'))" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/></strong>
<strong><span class="text-nowrap" t-out="sum(o.env['account.move.line'].search([('partner_id', '=', o.partner_id.commercial_partner_id.id), ('account_id.account_type', '=', o.partner_type=='customer' and 'asset_receivable' or 'liability_payable'), ('reconciled', '=', False), ('account_id.deprecated', '=', False), ('move_id.state', '=', 'posted'), ('company_id', '=', o.company_id.id)]).mapped('amount_residual'))" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/></strong>
</td>
</tr>
</tfoot>
Expand Down

0 comments on commit 37fef50

Please sign in to comment.