-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] account_multicompany_ux: new wizard to change company on invoices
Lo hacemos por estos motivos: a) tenemos muchos errores en distintos casos (viniendo desde OC, cambiando partner y luego cia, etc). Tanto depends/onchange lo hace super complicado b) además con esto nos evitamos necesitar el pr odoo/odoo#121725
- Loading branch information
1 parent
35365e6
commit f11a349
Showing
8 changed files
with
131 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_res_company_property,access_res_company_property,model_res_company_property,base.group_user,1,1,1,1 | ||
account_multicompany_ux.access_account_change_company,access_account_change_company,account_multicompany_ux.model_account_change_company,base.group_user,1,1,1,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<odoo> | ||
|
||
<record id="view_move_form" model="ir.ui.view"> | ||
<field name="model">account.move</field> | ||
<field name="name">account.move.form</field> | ||
<field name="inherit_id" ref="account.view_move_form"/> | ||
<field name="arch" type="xml"> | ||
<label for="journal_id" position="before"> | ||
<label for="company_id" readonly="True" groups="base.group_multi_company"/> | ||
<div groups="base.group_multi_company"> | ||
<field name="company_id" readonly="True" class="oe_inline"/> | ||
<button name="%(action_account_change_company)d" type="action" attrs="{'invisible':[('state','!=','draft')]}" icon="fa-pencil" class="btn-link" title="Change Company" /> | ||
</div> | ||
</label> | ||
|
||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from . import account_change_company |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from odoo import fields, models, api, _ | ||
|
||
|
||
class AccountChangeCurrency(models.TransientModel): | ||
_name = 'account.change.company' | ||
_description = 'Change Company' | ||
|
||
@api.model | ||
def get_move(self): | ||
move = self.env['account.move'].browse( | ||
self._context.get('active_id', False)) | ||
return move | ||
|
||
move_id = fields.Many2one('account.move', default=get_move) | ||
company_ids = fields.Many2many('res.company', compute='_compute_company_ids') | ||
company_id = fields.Many2one( | ||
'res.company', required=True, ondelete='cascade', | ||
compute='_compute_company', store=True, readonly=False) | ||
journal_id = fields.Many2one( | ||
'account.journal', required=True, ondelete='cascade', domain="[('id', 'in', suitable_journal_ids)]", | ||
store=True, compute='_compute_journal', readonly=False) | ||
suitable_journal_ids = fields.Many2many( | ||
'account.journal', | ||
compute='_compute_suitable_journal_ids', | ||
) | ||
|
||
@api.depends('move_id') | ||
@api.depends_context('allowed_company_ids') | ||
def _compute_company_ids(self): | ||
self.company_ids = self.env.companies - self.move_id.company_id | ||
|
||
@api.depends('company_ids') | ||
def _compute_company(self): | ||
for rec in self: | ||
rec.company_id = self.company_ids[:1] | ||
|
||
@api.depends('suitable_journal_ids') | ||
def _compute_journal(self): | ||
for rec in self: | ||
rec.journal_id = rec.suitable_journal_ids[:1] | ||
|
||
@api.depends('move_id', 'company_id') | ||
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 | ||
For this to work the pr is needed https://github.com/odoo/odoo/pull | ||
""" | ||
for rec in self: | ||
journal_type = rec.move_id.invoice_filter_type_domain or 'general' | ||
domain = [('company_id', '=', rec.company_id._origin.id), ('type', '=', journal_type)] | ||
rec.suitable_journal_ids = self.env['account.journal'].search(domain) | ||
|
||
def change_company(self): | ||
self.ensure_one() | ||
self.move_id.write({ | ||
'company_id': self.company_id.id, | ||
'journal_id': self.journal_id.id, | ||
}) | ||
self.move_id._compute_partner_bank_id() | ||
# si el payment term tiene compañía y es distinta a la que elegimos, forzamos recomputo | ||
if self.move_id.invoice_payment_term_id.company_id and self.move_id.invoice_payment_term_id.company_id != self.company_id: | ||
self.move_id._compute_invoice_payment_term_id() | ||
self.move_id.line_ids.with_company(self.company_id.id)._compute_account_id() | ||
self.move_id.invoice_line_ids.with_company(self.company_id.id)._compute_tax_ids() | ||
for invoice_line in self.move_id.invoice_line_ids.filtered(lambda x: not x.product_id).with_company(self.company_id.id): | ||
invoice_line.tax_ids = invoice_line._get_computed_taxes() |
33 changes: 33 additions & 0 deletions
33
account_multicompany_ux/wizards/account_change_company_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_account_change_company" model="ir.ui.view"> | ||
<field name="name">Change Company</field> | ||
<field name="model">account.change.company</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<group> | ||
<field name="move_id" invisible="1"/> | ||
<field name="suitable_journal_ids" invisible="1"/> | ||
<field name="company_ids" invisible="1"/> | ||
<field name="company_id" domain="[('id', 'in', company_ids)]"/> | ||
<field name="journal_id"/> | ||
</group> | ||
<footer> | ||
<button name="change_company" string="Change Company" type="object" class="oe_highlight"/> | ||
or | ||
<button string="Cancel" class="oe_link" special="cancel"/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_account_change_company" model="ir.actions.act_window"> | ||
<field name="name">Change Company</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">account.change.company</field> | ||
<field name="view_mode">form</field> | ||
<field name="view_id" ref="view_account_change_company"/> | ||
<field name="context">{}</field> | ||
<field name="target">new</field> | ||
</record> | ||
</odoo> |