Skip to content

Commit

Permalink
[IMP] account: add context in invoice onchange_partner_id method
Browse files Browse the repository at this point in the history
(Manual rebase of PR odoo#915)
  • Loading branch information
rvalyi authored and odony committed Jul 5, 2014
1 parent 7cc95f1 commit d78192c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
15 changes: 10 additions & 5 deletions addons/account/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,10 @@ def unlink(self, cr, uid, ids, context=None):
osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
return True

def onchange_partner_id(self, cr, uid, ids, type, partner_id,\
date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False, context=None):
def onchange_partner_id(self, cr, uid, ids, type, partner_id,
date_invoice=False, payment_term=False,
partner_bank_id=False, company_id=False,
context=None):
partner_payment_term = False
acc_id = False
bank_id = False
Expand All @@ -481,7 +483,8 @@ def onchange_partner_id(self, cr, uid, ids, type, partner_id,\
if partner_id:

opt.insert(0, ('id', partner_id))
p = self.pool.get('res.partner').browse(cr, uid, partner_id)
p = self.pool.get('res.partner').browse(cr, uid, partner_id,
context=context)
if company_id:
if (p.property_account_receivable.company_id and (p.property_account_receivable.company_id.id != company_id)) and (p.property_account_payable.company_id and (p.property_account_payable.company_id.id != company_id)):
property_obj = self.pool.get('ir.property')
Expand All @@ -500,8 +503,10 @@ def onchange_partner_id(self, cr, uid, ids, type, partner_id,\
msg = _('Cannot find a chart of accounts for this company, You should configure it. \nPlease go to Account Configuration.')
raise openerp.exceptions.RedirectWarning(msg, action_id, _('Go to the configuration panel'))
account_obj = self.pool.get('account.account')
rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])
pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])
rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id],
context=context)
pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id],
context=context)
p.property_account_receivable = rec_obj_acc[0]
p.property_account_payable = pay_obj_acc[0]

Expand Down
4 changes: 2 additions & 2 deletions addons/account/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<group>
<group>
<field string="Supplier" name="partner_id"
on_change="onchange_partner_id(type,partner_id,date_invoice,payment_term, partner_bank_id,company_id)"
on_change="onchange_partner_id(type, partner_id, date_invoice, payment_term, partner_bank_id, company_id, context)"
context="{'default_customer': 0, 'search_default_supplier': 1, 'default_supplier': 1}"
domain="[('supplier', '=', True)]"/>
<field name="fiscal_position" options="{'no_create': True}"/>
Expand Down Expand Up @@ -320,7 +320,7 @@
<group>
<group>
<field string="Customer" name="partner_id"
on_change="onchange_partner_id(type,partner_id,date_invoice,payment_term, partner_bank_id,company_id)"
on_change="onchange_partner_id(type, partner_id, date_invoice, payment_term, partner_bank_id, company_id, context)"
context="{'search_default_customer':1, 'show_address': 1}"
options='{"always_reload": True}'
domain="[('customer', '=', True)]"/>
Expand Down
10 changes: 6 additions & 4 deletions addons/l10n_be_invoice_bba/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ def _check_communication(self, cr, uid, ids):
return True

def onchange_partner_id(self, cr, uid, ids, type, partner_id,
date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
date_invoice=False, payment_term=False,
partner_bank_id=False, company_id=False,
context=None):
result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
date_invoice, payment_term, partner_bank_id, company_id)
date_invoice, payment_term, partner_bank_id, company_id, context)
# reference_type = self.default_get(cr, uid, ['reference_type'])['reference_type']
# _logger.warning('partner_id %s' % partner_id)
reference = False
reference_type = 'none'
if partner_id:
if (type == 'out_invoice'):
reference_type = self.pool.get('res.partner').browse(cr, uid, partner_id).out_inv_comm_type
reference_type = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context).out_inv_comm_type
if reference_type:
reference = self.generate_bbacomm(cr, uid, ids, type, reference_type, partner_id, '', context={})['value']['reference']
reference = self.generate_bbacomm(cr, uid, ids, type, reference_type, partner_id, '', context=context)['value']['reference']
res_update = {
'reference_type': reference_type or 'none',
'reference': reference,
Expand Down
8 changes: 5 additions & 3 deletions addons/warning/warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def onchange_partner_id(self, cr, uid, ids, part, context=None):
class account_invoice(osv.osv):
_inherit = 'account.invoice'
def onchange_partner_id(self, cr, uid, ids, type, partner_id,
date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
date_invoice=False, payment_term=False,
partner_bank_id=False, company_id=False,
context=None):
if not partner_id:
return {'value': {
'account_id': False,
Expand All @@ -121,7 +123,7 @@ def onchange_partner_id(self, cr, uid, ids, type, partner_id,
warning = {}
title = False
message = False
partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
if partner.invoice_warn != 'no-message':
title = _("Warning for %s") % partner.name
message = partner.invoice_warn_msg
Expand All @@ -135,7 +137,7 @@ def onchange_partner_id(self, cr, uid, ids, type, partner_id,

result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
date_invoice=date_invoice, payment_term=payment_term,
partner_bank_id=partner_bank_id, company_id=company_id)
partner_bank_id=partner_bank_id, company_id=company_id, context=context)

if result.get('warning',False):
warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
Expand Down

0 comments on commit d78192c

Please sign in to comment.