'''
Find the partner for which the accounting entries will be created
'''
- #if the chosen partner is not a company and has a parent company, use the parent for the journal entries
+ #if the chosen partner is not a company and has a parent company, use the parent for the journal entries
#because you want to invoice 'Agrolait, accounting department' but the journal items are for 'Agrolait'
part = inv.partner_id
if part.parent_id and not part.is_company:
try:
compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
except ValueError:
- compose_form_id = False
+ compose_form_id = False
ctx = dict(context)
ctx.update({
'default_model': 'account.invoice',
return result
def onchange_payment_term_date_invoice(self, cr, uid, ids, payment_term_id, date_invoice):
- res = {}
+ res = {}
if not date_invoice:
date_invoice = time.strftime('%Y-%m-%d')
if not payment_term_id:
- return {'value':{'date_due': date_invoice}} #To make sure the invoice has a due date when no payment term
+ return {'value':{'date_due': date_invoice}} #To make sure the invoice has a due date when no payment term
pterm_list = self.pool.get('account.payment.term').compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice)
if pterm_list:
pterm_list = [line[0] for line in pterm_list]
def onchange_partner_bank(self, cursor, user, ids, partner_bank_id=False):
return {'value': {}}
- def onchange_company_id(self, cr, uid, ids, company_id, part_id, type, invoice_line, currency_id):
+ def onchange_company_id(self, cr, uid, ids, company_id, part_id, type, invoice_line, currency_id, context=None):
val = {}
dom = {}
obj_journal = self.pool.get('account.journal')
account_obj = self.pool.get('account.account')
inv_line_obj = self.pool.get('account.invoice.line')
+
if company_id and part_id and type:
acc_id = False
- partner_obj = self.pool.get('res.partner').browse(cr,uid,part_id)
+ partner_obj = self.pool.get('res.partner').browse(cr, uid, part_id, context=context)
+
if partner_obj.property_account_payable and partner_obj.property_account_receivable:
if partner_obj.property_account_payable.company_id.id != company_id and partner_obj.property_account_receivable.company_id.id != company_id:
property_obj = self.pool.get('ir.property')
rec_pro_id = property_obj.search(cr, uid, [('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(part_id)+''),('company_id','=',company_id)])
pay_pro_id = property_obj.search(cr, uid, [('name','=','property_account_payable'),('res_id','=','res.partner,'+str(part_id)+''),('company_id','=',company_id)])
+
if not rec_pro_id:
rec_pro_id = property_obj.search(cr, uid, [('name','=','property_account_receivable'),('company_id','=',company_id)])
if not pay_pro_id:
pay_pro_id = property_obj.search(cr, uid, [('name','=','property_account_payable'),('company_id','=',company_id)])
+
rec_line_data = property_obj.read(cr, uid, rec_pro_id, ['name','value_reference','res_id'])
pay_line_data = property_obj.read(cr, uid, pay_pro_id, ['name','value_reference','res_id'])
rec_res_id = rec_line_data and rec_line_data[0].get('value_reference',False) and int(rec_line_data[0]['value_reference'].split(',')[1]) or False
pay_res_id = pay_line_data and pay_line_data[0].get('value_reference',False) and int(pay_line_data[0]['value_reference'].split(',')[1]) or False
+
if not rec_res_id and not pay_res_id:
- raise osv.except_osv(_('Configuration Error!'),
- _('Cannot find a chart of account, you should create one from Settings\Configuration\Accounting menu.'))
+ raise self.pool.get('res.config.settings').get_config_warning(cr, _('Cannot find any chart of account: you can create a new one from %(menu:account.menu_account_config)s.'), context=context)
+
if type in ('out_invoice', 'out_refund'):
acc_id = rec_res_id
else:
acc_id = pay_res_id
+
val= {'account_id': acc_id}
if ids:
if company_id: