Skip to content

Commit

Permalink
[IMP] account_multic_fix: change taxes on invoice lines if journal is…
Browse files Browse the repository at this point in the history
… changed
  • Loading branch information
pablohmontenegro committed Apr 17, 2023
1 parent 0f8d5a5 commit bbfd283
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions account_multic_fix/models/account_move.py
Expand Up @@ -10,6 +10,74 @@ class AccountMove(models.Model):



def _onchange_journal_id(self):
company_changed = False
if self._origin.company_id:
company_changed = self.company_id != self._origin.company_id
#if self.line_ids:
# company_changed = self.company_id != self.line_ids[0].account_id.company_id
#elif self.invoice_partner_bank_id.company_id and self.invoice_partner_bank_id.company_id != self.company_id:
# company_changed = True
elif self.invoice_payment_term_id.company_id and self.invoice_payment_term_id.company_id != self.company_id:
company_changed = True
elif self.fiscal_position_id.company_id and self.fiscal_position_id.company_id != self.company_id:
company_changed = True
if company_changed:
# self = self.with_context(force_company=self.company_id.id)
# si cambiamos la compania queremos actualizar cuenta bancaria, termino de pago, apuntes de deuda, etc.
# este metodo refrezca tmb las lineas de deuda
self._onchange_partner_id()
# update lines
for line in self.invoice_line_ids:
# we force cache update of company_id value on invoice lines
# this fix right tax choose
# prevent price and name being overwrited
price_unit = line.price_unit
name = line.name
product_uom = line.product_uom_id
line.company_id = self.company_id
#line._onchange_product_id()
line.name = name
line.price_unit = price_unit
line.product_uom_id = product_uom

# To prevent the mixen company with account and taxes when the line doesn't have a product,
# we force to choose a new account after change the journal for a different company
#if any([line.company_id.id != l.company_id.id for l in line.tax_ids]):
# taxes = line._get_computed_taxes()
# if taxes and line.move_id.fiscal_position_id:
# taxes = line.move_id.fiscal_position_id.map_tax(taxes, partner=line.partner_id)
# if not line.display_type and not line.product_id:
# if line.account_id.company_id != line.company_id:
# if line.move_id.is_sale_document(include_receipts=True):
# line.account_id = line.move_id.journal_id.default_account_id
# elif line.move_id.is_purchase_document(include_receipts=True):
# line.account_id = line.move_id.journal_id.default_account_id
# if any([line.company_id.id != l.company_id.id for l in line.tax_ids]):
# taxes = line._get_computed_taxes()
# if taxes and line.move_id.fiscal_position_id:
# taxes = line.move_id.fiscal_position_id.map_tax(taxes, partner=line.partner_id)
# line.tax_ids = taxes or [(5,0,0)]
# we need to force change currency
#if self.currency_id != self.company_id.currency_id:
# self._onchange_currency()
# si bien onchange partner llama _recompute_dynamic_lines no manda el recompute_all_taxes, este refrezca
# lineas de impuestos+
#self._recompute_dynamic_lines(recompute_all_taxes=True)

#line_ids_commands.append(Command.update(line.id, {
# 'balance': balance,
# 'amount_currency': amount_currency,
# 'tax_tag_ids': to_update['tax_tag_ids'],
#}))
#invoice.write({'line_ids': [
#Command.update(tax_10_line.id, {'account_id': self.revenue_2.id}),
#Command.update(tax_20_line.id, {'account_id': self.revenue_2.id, 'credit': 201.0}),
#Command.update(receivable_line.id, {'debit': 1301.0}),
#]})
# ver de hacer algo similar a esto def action_update_taxes(self):
return super()._onchange_journal_id()

@api.depends('company_id', 'invoice_filter_type_domain')
def _compute_suitable_journal_ids(self):
# we override this method to add filter by companies in the env instead of the company of the user
Expand Down

0 comments on commit bbfd283

Please sign in to comment.