diff --git a/addons/account/account.py b/addons/account/account.py index c1a30967aea..75bfc891980 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1079,7 +1079,7 @@ class account_period(osv.osv): def build_ctx_periods(self, cr, uid, period_from_id, period_to_id): if period_from_id == period_to_id: - return period_from_id + return [period_from_id] period_from = self.browse(cr, uid, period_from_id) period_date_start = period_from.date_start company1_id = period_from.company_id.id @@ -1652,7 +1652,7 @@ class account_move_reconcile(osv.osv): 'create_date': fields.date('Creation date', readonly=True), } _defaults = { - 'name': lambda self,cr,uid,ctx={}: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile') or '/', + 'name': lambda self,cr,uid,ctx=None: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile', context=ctx) or '/', } def reconcile_partial_check(self, cr, uid, ids, type='auto', context=None): @@ -1841,7 +1841,7 @@ class account_tax(osv.osv): PERCENT: tax = price * amount FIXED: tax = price + amount NONE: no tax line - CODE: execute python code. localcontext = {'price_unit':pu, 'address':address_object} + CODE: execute python code. localcontext = {'price_unit':pu} return result in the context Ex: result=round(price_unit*0.21,4) """ @@ -1963,8 +1963,8 @@ class account_tax(osv.osv): return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] _defaults = { - 'python_compute': '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or None\n# partner: res.partner object or None\n\nresult = price_unit * 0.10''', - 'python_compute_inv': '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or False\n\nresult = price_unit * 0.10''', + 'python_compute': '''# price_unit\n# or False\n# product: product.product object or None\n# partner: res.partner object or None\n\nresult = price_unit * 0.10''', + 'python_compute_inv': '''# price_unit\n# product: product.product object or False\n\nresult = price_unit * 0.10''', 'applicable_type': 'true', 'type': 'percent', 'amount': 0, @@ -1981,12 +1981,11 @@ class account_tax(osv.osv): } _order = 'sequence' - def _applicable(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None): + def _applicable(self, cr, uid, taxes, price_unit, product=None, partner=None): res = [] - obj_partener_address = self.pool.get('res.partner.address') for tax in taxes: if tax.applicable_type=='code': - localdict = {'price_unit':price_unit, 'address':obj_partener_address.browse(cr, uid, address_id), 'product':product, 'partner':partner} + localdict = {'price_unit':price_unit, 'product':product, 'partner':partner} exec tax.python_applicable in localdict if localdict.get('result', False): res.append(tax) @@ -1994,11 +1993,10 @@ class account_tax(osv.osv): res.append(tax) return res - def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None, quantity=0): - taxes = self._applicable(cr, uid, taxes, price_unit, address_id, product, partner) + def _unit_compute(self, cr, uid, taxes, price_unit, product=None, partner=None, quantity=0): + taxes = self._applicable(cr, uid, taxes, price_unit ,product, partner) res = [] cur_price_unit=price_unit - obj_partener_address = self.pool.get('res.partner.address') for tax in taxes: # we compute the amount for the current tax object and append it to the result data = {'id':tax.id, @@ -2026,8 +2024,7 @@ class account_tax(osv.osv): data['tax_amount']=quantity # data['amount'] = quantity elif tax.type=='code': - address = address_id and obj_partener_address.browse(cr, uid, address_id) or None - localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner} + localdict = {'price_unit':cur_price_unit, 'product':product, 'partner':partner} exec tax.python_compute in localdict amount = localdict['result'] data['amount'] = amount @@ -2040,7 +2037,7 @@ class account_tax(osv.osv): if tax.child_depend: latest = res.pop() amount = amount2 - child_tax = self._unit_compute(cr, uid, tax.child_ids, amount, address_id, product, partner, quantity) + child_tax = self._unit_compute(cr, uid, tax.child_ids, amount, product, partner, quantity) res.extend(child_tax) if tax.child_depend: for r in res: @@ -2060,7 +2057,7 @@ class account_tax(osv.osv): cur_price_unit+=amount2 return res - def compute_all(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None, force_excluded=False): + def compute_all(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None, force_excluded=False): """ :param force_excluded: boolean used to say that we don't want to consider the value of field price_include of tax. It's used in encoding by line where you don't matter if you encoded a tax with that boolean to True or @@ -2080,7 +2077,7 @@ class account_tax(osv.osv): tex.append(tax) else: tin.append(tax) - tin = self.compute_inv(cr, uid, tin, price_unit, quantity, address_id=address_id, product=product, partner=partner) + tin = self.compute_inv(cr, uid, tin, price_unit, quantity, product=product, partner=partner) for r in tin: totalex -= r.get('amount', 0.0) totlex_qty = 0.0 @@ -2088,7 +2085,7 @@ class account_tax(osv.osv): totlex_qty = totalex/quantity except: pass - tex = self._compute(cr, uid, tex, totlex_qty, quantity, address_id=address_id, product=product, partner=partner) + tex = self._compute(cr, uid, tex, totlex_qty, quantity,product=product, partner=partner) for r in tex: totalin += r.get('amount', 0.0) return { @@ -2097,13 +2094,13 @@ class account_tax(osv.osv): 'taxes': tin + tex } - def compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): + def compute(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None): logger = netsvc.Logger() logger.notifyChannel("warning", netsvc.LOG_WARNING, "Deprecated, use compute_all(...)['taxes'] instead of compute(...) to manage prices with tax included") - return self._compute(cr, uid, taxes, price_unit, quantity, address_id, product, partner) + return self._compute(cr, uid, taxes, price_unit, quantity, product, partner) - def _compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): + def _compute(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None): """ Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID. @@ -2112,7 +2109,7 @@ class account_tax(osv.osv): tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2} one tax for each tax id in IDS and their children """ - res = self._unit_compute(cr, uid, taxes, price_unit, address_id, product, partner, quantity) + res = self._unit_compute(cr, uid, taxes, price_unit, product, partner, quantity) total = 0.0 precision_pool = self.pool.get('decimal.precision') for r in res: @@ -2123,9 +2120,8 @@ class account_tax(osv.osv): total += r['amount'] return res - def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None): - taxes = self._applicable(cr, uid, taxes, price_unit, address_id, product, partner) - obj_partener_address = self.pool.get('res.partner.address') + def _unit_compute_inv(self, cr, uid, taxes, price_unit, product=None, partner=None): + taxes = self._applicable(cr, uid, taxes, price_unit, product, partner) res = [] taxes.reverse() cur_price_unit = price_unit @@ -2150,8 +2146,7 @@ class account_tax(osv.osv): amount = tax.amount elif tax.type=='code': - address = address_id and obj_partener_address.browse(cr, uid, address_id) or None - localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner} + localdict = {'price_unit':cur_price_unit, 'product':product, 'partner':partner} exec tax.python_compute_inv in localdict amount = localdict['result'] elif tax.type=='balance': @@ -2185,7 +2180,7 @@ class account_tax(osv.osv): del res[-1] amount = price_unit - parent_tax = self._unit_compute_inv(cr, uid, tax.child_ids, amount, address_id, product, partner) + parent_tax = self._unit_compute_inv(cr, uid, tax.child_ids, amount, product, partner) res.extend(parent_tax) total = 0.0 @@ -2197,7 +2192,7 @@ class account_tax(osv.osv): r['todo'] = 0 return res - def compute_inv(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): + def compute_inv(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None): """ Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID. Price Unit is a VAT included price @@ -2207,7 +2202,7 @@ class account_tax(osv.osv): tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2} one tax for each tax id in IDS and their children """ - res = self._unit_compute_inv(cr, uid, taxes, price_unit, address_id, product, partner=None) + res = self._unit_compute_inv(cr, uid, taxes, price_unit, product, partner=None) total = 0.0 obj_precision = self.pool.get('decimal.precision') for r in res: @@ -2806,8 +2801,8 @@ class account_tax_template(osv.osv): return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] _defaults = { - 'python_compute': lambda *a: '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or None\n# partner: res.partner object or None\n\nresult = price_unit * 0.10''', - 'python_compute_inv': lambda *a: '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or False\n\nresult = price_unit * 0.10''', + 'python_compute': lambda *a: '''# price_unit\n# product: product.product object or None\n# partner: res.partner object or None\n\nresult = price_unit * 0.10''', + 'python_compute_inv': lambda *a: '''# price_unit\n# product: product.product object or False\n\nresult = price_unit * 0.10''', 'applicable_type': 'true', 'type': 'percent', 'amount': 0, diff --git a/addons/account/account_bank.py b/addons/account/account_bank.py index 5a84dee53de..cbc5a966f79 100644 --- a/addons/account/account_bank.py +++ b/addons/account/account_bank.py @@ -55,7 +55,7 @@ class bank(osv.osv): # Find the code and parent of the bank account to create dig = 6 current_num = 1 - ids = obj_acc.search(cr, uid, [('type','=','liquidity')], context=context) + ids = obj_acc.search(cr, uid, [('type','=','liquidity'), ('company_id', '=', bank.company_id.id)], context=context) # No liquidity account exists, no template available if not ids: continue diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index c1f787f5d80..5601179e0fc 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -341,11 +341,11 @@ class account_bank_statement(osv.osv): if not st.name == '/': st_number = st.name else: + c = {'fiscalyear_id': st.period_id.fiscalyear_id.id} if st.journal_id.sequence_id: - c = {'fiscalyear_id': st.period_id.fiscalyear_id.id} st_number = obj_seq.next_by_id(cr, uid, st.journal_id.sequence_id.id, context=c) else: - st_number = obj_seq.next_by_code(cr, uid, 'account.bank.statement') + st_number = obj_seq.next_by_code(cr, uid, 'account.bank.statement', context=c) for line in st.move_line_ids: if line.state <> 'valid': diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 2768fd83019..f19c1e1c639 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -279,11 +279,11 @@ class account_cash_statement(osv.osv): raise osv.except_osv(_('Error !'), (_('User %s does not have rights to access %s journal !') % (statement.user_id.name, statement.journal_id.name))) if statement.name and statement.name == '/': + c = {'fiscalyear_id': statement.period_id.fiscalyear_id.id} if statement.journal_id.sequence_id: - c = {'fiscalyear_id': statement.period_id.fiscalyear_id.id} st_number = obj_seq.next_by_id(cr, uid, statement.journal_id.sequence_id.id, context=c) else: - st_number = obj_seq.next_by_code(cr, uid, 'account.cash.statement') + st_number = obj_seq.next_by_code(cr, uid, 'account.cash.statement', context=c) vals.update({ 'name': st_number }) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 5e5ac5f482b..700936695b8 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -216,8 +216,6 @@ class account_invoice(osv.osv): help="If you use payment terms, the due date will be computed automatically at the generation "\ "of accounting entries. If you keep the payment term and the due date empty, it means direct payment. The payment term may compute several due dates, for example 50% now, 50% in one month."), 'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True, states={'draft':[('readonly',False)]}), - 'address_contact_id': fields.many2one('res.partner.address', 'Contact Address', readonly=True, states={'draft':[('readonly',False)]}), - 'address_invoice_id': fields.many2one('res.partner.address', 'Invoice Address', readonly=True, required=True, states={'draft':[('readonly',False)]}), 'payment_term': fields.many2one('account.payment.term', 'Payment Term',readonly=True, states={'draft':[('readonly',False)]}, help="If you use payment terms, the due date will be computed automatically at the generation "\ "of accounting entries. If you keep the payment term and the due date empty, it means direct payment. "\ @@ -396,7 +394,6 @@ class account_invoice(osv.osv): def onchange_partner_id(self, cr, uid, ids, type, partner_id,\ date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False): invoice_addr_id = False - contact_addr_id = False partner_payment_term = False acc_id = False bank_id = False @@ -406,8 +403,7 @@ class account_invoice(osv.osv): if partner_id: opt.insert(0, ('id', partner_id)) - res = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['contact', 'invoice']) - contact_addr_id = res['contact'] + res = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['invoice']) invoice_addr_id = res['invoice'] p = self.pool.get('res.partner').browse(cr, uid, partner_id) if company_id: @@ -442,8 +438,6 @@ class account_invoice(osv.osv): bank_id = p.bank_ids[0].id result = {'value': { - 'address_contact_id': contact_addr_id, - 'address_invoice_id': invoice_addr_id, 'account_id': acc_id, 'payment_term': partner_payment_term, 'fiscal_position': fiscal_position @@ -1092,7 +1086,7 @@ class account_invoice(osv.osv): return map(lambda x: (0,0,x), lines) def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None): - invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id']) + invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id']) obj_invoice_line = self.pool.get('account.invoice.line') obj_invoice_tax = self.pool.get('account.invoice.tax') obj_journal = self.pool.get('account.journal') @@ -1140,7 +1134,7 @@ class account_invoice(osv.osv): 'name': description, }) # take the id part of the tuple returned for many2one fields - for field in ('address_contact_id', 'address_invoice_id', 'partner_id', + for field in ('partner_id', 'account_id', 'currency_id', 'payment_term', 'journal_id'): invoice[field] = invoice[field] and invoice[field][0] # create the new invoice @@ -1257,7 +1251,7 @@ class account_invoice_line(osv.osv): cur_obj = self.pool.get('res.currency') for line in self.browse(cr, uid, ids): price = line.price_unit * (1-(line.discount or 0.0)/100.0) - taxes = tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, price, line.quantity, product=line.product_id, address_id=line.invoice_id.address_invoice_id, partner=line.invoice_id.partner_id) + taxes = tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, price, line.quantity, product=line.product_id, partner=line.invoice_id.partner_id) res[line.id] = taxes['total'] if line.invoice_id: cur = line.invoice_id.currency_id @@ -1277,7 +1271,7 @@ class account_invoice_line(osv.osv): taxes = l[2].get('invoice_line_tax_id') if len(taxes[0]) >= 3 and taxes[0][2]: taxes = tax_obj.browse(cr, uid, list(taxes[0][2])) - for tax in tax_obj.compute_all(cr, uid, taxes, p,l[2].get('quantity'), context.get('address_invoice_id', False), l[2].get('product_id', False), context.get('partner_id', False))['taxes']: + for tax in tax_obj.compute_all(cr, uid, taxes, p,l[2].get('quantity'), l[2].get('product_id', False), context.get('partner_id', False))['taxes']: t = t - tax['amount'] return t return 0 @@ -1322,7 +1316,7 @@ class account_invoice_line(osv.osv): res['arch'] = etree.tostring(doc) return res - def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None, company_id=None): + def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, context=None, company_id=None): if context is None: context = {} company_id = company_id if company_id != None else context.get('company_id',False) @@ -1397,14 +1391,14 @@ class account_invoice_line(osv.osv): res_final['value']['price_unit'] = new_price return res_final - def uos_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None, company_id=None): + def uos_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, context=None, company_id=None): if context is None: context = {} company_id = company_id if company_id != None else context.get('company_id',False) context = dict(context) context.update({'company_id': company_id}) warning = {} - res = self.product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id, context=context) + res = self.product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, currency_id, context=context) if 'uos_id' in res['value']: del res['value']['uos_id'] if not uom: @@ -1437,7 +1431,7 @@ class account_invoice_line(osv.osv): tax_code_found= False for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, (line.price_unit * (1.0 - (line['discount'] or 0.0) / 100.0)), - line.quantity, inv.address_invoice_id.id, line.product_id, + line.quantity, line.product_id, inv.partner_id)['taxes']: if inv.type in ('out_invoice', 'in_invoice'): @@ -1572,7 +1566,7 @@ class account_invoice_tax(osv.osv): company_currency = inv.company_id.currency_id.id for line in inv.invoice_line: - for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, (line.price_unit* (1-(line.discount or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id, inv.partner_id)['taxes']: + for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, (line.price_unit* (1-(line.discount or 0.0)/100.0)), line.quantity, line.product_id, inv.partner_id)['taxes']: tax['price_unit'] = cur_obj.round(cr, uid, cur, tax['price_unit']) val={} val['invoice_id'] = inv.id diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 07443b58974..ef6c2510c54 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -51,12 +51,12 @@ form
- +