Skip to content

Commit

Permalink
[MIG] account_multic_fix: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohmontenegro authored and jjscarafia committed Jan 10, 2023
1 parent 645d84c commit 2dab25e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 85 deletions.
1 change: 0 additions & 1 deletion account_multic_fix/README.rst
Expand Up @@ -16,7 +16,6 @@ Account Multi Company Fixes

#. Add check_company on account.move and account.move.line (backported from odoo master https://github.com/odoo/odoo/commit/847889b49768db290f86ab5c5f48e8134fa29266) (TODO remove on v14)
#. Some fixes so that you can change to a journal of different company and everthing is updated correctly
#. Don´t allow to change the journal if the state of the invoice is cancelled.

TODO (Viejo):
arreglar para los statments, por ahora no pudismo hacer que nade bien, sobre todo la parte de que
Expand Down
5 changes: 2 additions & 3 deletions account_multic_fix/__manifest__.py
Expand Up @@ -19,15 +19,14 @@
##############################################################################
{
'name': 'Account Multi Company Fixes',
'version': "15.0.1.0.0",
'version': "16.0.1.0.0",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'category': 'Accounting & Finance',
'depends': ['account'],
'data': [
'views/account_bank_statement_line_views.xml',
],
'demo': [],
'installable': False,
'installable': True,
}
68 changes: 1 addition & 67 deletions account_multic_fix/models/account_move.py
Expand Up @@ -2,72 +2,13 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, api, _
from odoo.exceptions import UserError
from odoo import models, api


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

@api.onchange('journal_id')
def _onchange_journal(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.partner_bank_id.company_id and self.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 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)
return super()._onchange_journal()

@api.onchange('partner_id')
def _onchange_partner_id(self):
res = super()._onchange_partner_id()
partner_banks = self.bank_partner_id.bank_ids.filtered(lambda x: x.company_id == self.company_id)
self.partner_bank_id = partner_banks and partner_banks[0]
return res

@api.depends('company_id', 'invoice_filter_type_domain')
def _compute_suitable_journal_ids(self):
Expand All @@ -77,10 +18,3 @@ def _compute_suitable_journal_ids(self):
company_ids = self.env.companies.ids
domain = [('company_id', 'in', company_ids), ('type', '=', journal_type)]
m.suitable_journal_ids = self.env['account.journal'].search(domain)

@api.constrains('journal_id')
def _check_invoice_state(self):
"""This method don´t allow to change the journal if the state of the invoice is 'cancel'"""
for inv in self:
if inv.state == 'cancel':
raise UserError(_('It is not possible to change the journal if the invoice is cancelled. You can edit it changing the invoice state to draft.'))
14 changes: 0 additions & 14 deletions account_multic_fix/views/account_bank_statement_line_views.xml

This file was deleted.

0 comments on commit 2dab25e

Please sign in to comment.