Skip to content

Commit

Permalink
[FIX] account_multic_fix: change company on invoices
Browse files Browse the repository at this point in the history
closes #122

Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
  • Loading branch information
jjscarafia committed Apr 27, 2023
1 parent 0f8d5a5 commit d7ef599
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
8 changes: 0 additions & 8 deletions account_multic_fix/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@
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

TODO (Viejo):
arreglar para los statments, por ahora no pudismo hacer que nade bien, sobre todo la parte de que
cuentas ofrece para seleccionar. Tal vez podemos ver de dejar eso de esa manera.
Al respecto de como se genera esto esta este codigo:
<table class="o_group o_inner_group o_group_col_6 create_group_right"><!-- here come some form_create_field --></table>

A su vez hay que cambiar self.env.company por self.journal_id.company_id en "account.bank.statement", tal vez un pr a odoo?

Installation
============
Expand Down
41 changes: 39 additions & 2 deletions account_multic_fix/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
class AccountMove(models.Model):
_inherit = "account.move"



@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 All @@ -18,3 +16,42 @@ 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.onchange("company_id")
def _onchange_company(self):
""" Similar a account_invoice_fiscal_position_update
Este metodo es necesario para recomputar impuestos al cambiar diario que cambie
compañía (las cuentas ya se recomputan bien solas)"""
res = {}
lines_without_product = self.env["account.move.line"]
invoice_lines = self.invoice_line_ids.filtered(
lambda l: "product" == l.display_type
)
for line in invoice_lines:
if not line.product_id:
lines_without_product |= line
else:
line._compute_tax_ids()
line._compute_account_id()
if lines_without_product:
res["warning"] = {"title": _("Warning")}
if len(lines_without_product) == len(invoice_lines):
res["warning"]["message"] = _(
"The invoice lines were not updated to the new "
"Fiscal Position because they don't have products. "
"You should update the Account and the Taxes of each "
"invoice line manually."
)
else:
res["warning"]["message"] = _(
"The following invoice lines were not updated "
"to the new Fiscal Position because they don't have a "
"Product:\n - %s\nYou should update the Account and the "
"Taxes of these invoice lines manually."
) % ("\n- ".join(lines_without_product.mapped("name")))
return res

@api.depends('company_id')
def _compute_partner_bank_id(self):
""" Update bank accounts if company is changed"""
super()._compute_partner_bank_id()

0 comments on commit d7ef599

Please sign in to comment.