Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions mcfix_account/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from odoo import models, api, _
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError


Expand Down Expand Up @@ -64,6 +64,15 @@ def _check_company_id(self):
class AccountAbstractPayment(models.AbstractModel):
_inherit = 'account.abstract.payment'

@api.multi
def _get_default_company(self):
if self.env.context.get('default_invoice_ids'):
inv = self.env['account.invoice'].browse(self.env.context['default_invoice_ids'][0][1])
return inv.company_id.id
return self.env.user.company_id.id

create_company_id = fields.Many2one('res.company', string='Company', default=_get_default_company)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 70 and 74 are >80 lines and so the linter complains and the PR is red

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not actively maintaing the v10 branch. I believe that by now it must be quite obsolete.

v11 is up to date. I suggest that you consider reviewing that branch first.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I have a customer on 10.0 who wants to use this :-)

I have realized 10.0 is behind, so am now testing 11.0 and considering the possibility of backporting some functionalities.


@api.multi
@api.depends('company_id')
def name_get(self):
Expand All @@ -79,10 +88,12 @@ def name_get(self):
res += [(rec.id, name)]
return res

@api.onchange('company_id')
def onchange_company_id(self):
self.journal_id = False
# @api.onchange('create_company_id')
# def onchange_company_id(self):
# if self.create_company_id and self.journal_id.company_id != self.create_company_id:
# self.journal_id = False
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented lines


# Company is related from journal_id cannot be different!!!!!
@api.multi
@api.constrains('journal_id', 'company_id')
def _check_company_journal_id(self):
Expand All @@ -96,6 +107,27 @@ def _check_company_journal_id(self):
return True


class AccountRegisterPayment(models.TransientModel):
_inherit = 'account.register.payments'

@api.model
def default_get(self, fields):
rec = super(AccountRegisterPayment, self).default_get(fields)
context = dict(self._context or {})
active_model = context.get('active_model')
active_ids = context.get('active_ids')
invoices = self.env[active_model].browse(active_ids)
if invoices:
rec['create_company_id'] = invoices[0].company_id.id
return rec

@api.onchange('create_company_id')
def onchange_company_id(self):
if self.create_company_id and \
self.journal_id.company_id != self.create_company_id:
self.journal_id = False


class AccountPayment(models.Model):
_inherit = "account.payment"

Expand Down Expand Up @@ -131,17 +163,26 @@ def _compute_destination_account_id(self):
force_company=rec.company_id.id).\
property_account_payable_id.id

@api.onchange('payment_type', 'company_id')
@api.onchange('create_company_id')
def onchange_company_id(self):
if self.create_company_id and \
self.journal_id.company_id != self.create_company_id:
self.journal_id = False
if self.create_company_id:
return self._onchange_payment_type()

@api.onchange('payment_type')
def _onchange_payment_type(self):
res = super(AccountPayment, self)._onchange_payment_type()
res['domain']['journal_id'].append(('company_id', '=',
self.company_id.id))
self.create_company_id.id))
return res

@api.model
def create(self, vals):
if 'company_id' not in vals:
journal_id = vals.get('journal_id')
journal = self.env['account.journal'].browse(journal_id)
vals['company_id'] = journal.company_id.id
return super(AccountPayment, self).create(vals)
# is related!!!
# @api.model
# def create(self, vals):
# if 'company_id' not in vals:
# journal_id = vals.get('journal_id')
# journal = self.env['account.journal'].browse(journal_id)
# vals['company_id'] = journal.company_id.id
# return super(AccountPayment, self).create(vals)
28 changes: 26 additions & 2 deletions mcfix_account/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
<field name="inherit_id" ref="account.view_account_payment_form"/>
<field name="arch" type="xml">
<field name="journal_id" position="before">
<field name="company_id" widget="selection" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="create_company_id" widget="selection" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="company_id" invisible='1'/>
</field>
<field name="journal_id" position="attributes">
<!-- Default - in case we don't call onchange -->
<attribute name="domain">[('type', 'in', ('bank', 'cash')), ('company_id','=', create_company_id)]</attribute>
<!-- Selection widget is buggy on client, if only domain changes!! -->
<attribute name='options'>{'no_create': True}</attribute>
<attribute name='widget'></attribute>
</field>
<field name="destination_journal_id" position="attributes">
<attribute name="domain">[('company_id','=', company_id)]</attribute>
<attribute name="domain">[('type', 'in', ('bank', 'cash')), ('company_id','=', company_id)]</attribute>
</field>
</field>
</record>
Expand All @@ -20,8 +28,24 @@
<field name="inherit_id" ref="account.view_account_payment_invoice_form"/>
<field name="arch" type="xml">
<field name="journal_id" position="before">
<field name="create_company_id" invisible="1"/>
<field name="company_id" invisible="1"/>
</field>
</field>
</record>

<record id="view_account_payment_from_invoices" model="ir.ui.view">
<field name="name">account.register.payments.wizard</field>
<field name="model">account.register.payments</field>
<field name='inherit_id' ref='account.view_account_payment_from_invoices'/>
<field name="arch" type="xml">
<field name="journal_id" position='before'>
<field name="create_company_id" invisible="1"/>
<field name='company_id' invisible='1'/>
</field>
<field name="journal_id" position='attributes'>
<attribute name='domain'>[('type', 'in', ('bank', 'cash')), ('company_id', '=', create_company_id)]</attribute>
</field>
</field>
</record>
</odoo>