[IMP] modified invoices in order to use fiscal position direclty on account.invoice instead of using the one from the partner.
bzr revid: qdp@tinyerp.com-20090119164929-st76nr5j75xrlwl8
This commit is contained in:
parent
ab00ab7e4a
commit
e61c5f97a8
|
@ -52,7 +52,7 @@
|
|||
<form string="Invoice Line">
|
||||
<notebook>
|
||||
<page string="Line">
|
||||
<field name="product_id" on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id)" select="1"/>
|
||||
<field name="product_id" on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position)" select="1"/>
|
||||
<field name="uos_id"/>
|
||||
<field name="quantity" select="1"/>
|
||||
<field name="price_unit" select="1"/>
|
||||
|
@ -154,8 +154,8 @@
|
|||
<field name="check_total" required="2"/>
|
||||
<field colspan="4" default_get="{'check_total': check_total, 'invoice_line': invoice_line, 'address_invoice_id': address_invoice_id, 'partner_id': partner_id, 'price_type': 'price_type' in dir() and price_type or False}" name="invoice_line" nolabel="1">
|
||||
<tree string="Invoice lines" editable="top">
|
||||
<field name="product_id" on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, price_unit, parent.address_invoice_id)"/>
|
||||
<field domain="[('company_id', '=', parent.company_id), ('journal_id', '=', parent.journal_id), ('type', '<>', 'view')]" name="account_id" on_change="onchange_account_id(parent.partner_id,account_id)"/>
|
||||
<field name="product_id" on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.address_invoice_id)"/>
|
||||
<field domain="[('company_id', '=', parent.company_id), ('journal_id', '=', parent.journal_id), ('type', '<>', 'view')]" name="account_id" on_change="onchange_account_id(parent.fiscal_position,account_id)"/>
|
||||
<field name="invoice_line_tax_id" view_mode="2" domain="[('parent_id','=',False)]"/>
|
||||
<field domain="[('type','<>','view'), ('company_id', '=', parent.company_id)]" name="account_analytic_id"/>
|
||||
<field name="quantity"/>
|
||||
|
|
|
@ -320,8 +320,7 @@ class account_invoice(osv.osv):
|
|||
acc_id = p.property_account_receivable.id
|
||||
else:
|
||||
acc_id = p.property_account_payable.id
|
||||
if p.property_account_position:
|
||||
fiscal_position = p.property_account_position.id
|
||||
fiscal_position = p.property_account_position and p.property_account_position.id or False
|
||||
partner_payment_term = p.property_payment_term and p.property_payment_term.id or False
|
||||
if p.bank_ids:
|
||||
bank_id = p.bank_ids[0].id
|
||||
|
@ -950,7 +949,7 @@ class account_invoice_line(osv.osv):
|
|||
price_unit = price_unit - tax['amount']
|
||||
return {'price_unit': price_unit,'invoice_line_tax_id': tax_id}
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, price_unit=False, address_invoice_id=False, context=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, address_invoice_id=False, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if not partner_id:
|
||||
|
@ -961,15 +960,17 @@ class account_invoice_line(osv.osv):
|
|||
else:
|
||||
return {'value': {'price_unit': 0.0}, 'domain':{'product_uom':[]}}
|
||||
part = self.pool.get('res.partner').browse(cr, uid, partner_id)
|
||||
fpos = fposition_id and self.pool.get('account.fiscal.position').browse(cr, uid, fposition_id) or False
|
||||
|
||||
lang=part.lang
|
||||
context.update({'lang': lang})
|
||||
res = self.pool.get('product.product').browse(cr, uid, product, context=context)
|
||||
taxep=None
|
||||
tax_obj = self.pool.get('account.tax')
|
||||
if type in ('out_invoice', 'out_refund'):
|
||||
tax_id = self.pool.get('account.fiscal.position').map_tax(cr, uid, part, res.taxes_id)
|
||||
tax_id = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, res.taxes_id)
|
||||
else:
|
||||
tax_id = self.pool.get('account.fiscal.position').map_tax(cr, uid, part, res.supplier_taxes_id)
|
||||
tax_id = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, res.supplier_taxes_id)
|
||||
if type in ('in_invoice', 'in_refund'):
|
||||
result = self.product_id_change_unit_price_inv(cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context=context)
|
||||
else:
|
||||
|
@ -987,7 +988,7 @@ class account_invoice_line(osv.osv):
|
|||
if not a:
|
||||
a = res.categ_id.property_account_expense_categ.id
|
||||
|
||||
a = self.pool.get('account.fiscal.position').map_account(cr, uid, part, a)
|
||||
a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
|
||||
if a:
|
||||
result['account_id'] = a
|
||||
|
||||
|
@ -1057,13 +1058,12 @@ class account_invoice_line(osv.osv):
|
|||
#
|
||||
# Set the tax field according to the account and the partner
|
||||
#
|
||||
def onchange_account_id(self, cr, uid, ids, partner_id,account_id):
|
||||
if not (partner_id and account_id):
|
||||
def onchange_account_id(self, cr, uid, ids, fposition_id, account_id):
|
||||
if not (fposition_id and account_id):
|
||||
return {}
|
||||
taxes = self.pool.get('account.account').browse(cr, uid, account_id).tax_ids
|
||||
part = self.pool.get('res.partner').browse(cr, uid, partner_id)
|
||||
|
||||
res = self.pool.get('account.fiscal.position').map_tax(cr, uid, part, taxes)
|
||||
fpos = fposition_id and self.pool.get('account.fiscal.position').browse(cr, uid, fposition_id) or False
|
||||
res = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes)
|
||||
r = {'value':{'invoice_line_tax_id': res}}
|
||||
return r
|
||||
account_invoice_line()
|
||||
|
|
|
@ -32,14 +32,15 @@ class account_fiscal_position(osv.osv):
|
|||
'account_ids': fields.one2many('account.fiscal.position.account', 'position_id', 'Accounts Mapping'),
|
||||
'tax_ids': fields.one2many('account.fiscal.position.tax', 'position_id', 'Taxes Mapping')
|
||||
}
|
||||
def map_tax(self, cr, uid, partner, taxes, context={}):
|
||||
if (not partner) or (not partner.property_account_position) :
|
||||
|
||||
def map_tax(self, cr, uid, fposition_id, taxes, context={}):
|
||||
if not fposition_id:
|
||||
return map(lambda x: x.id, taxes)
|
||||
result = []
|
||||
for t in taxes:
|
||||
ok = False
|
||||
for tax in partner.property_account_position.tax_ids:
|
||||
if tax.tax_src_id.id==t.id:
|
||||
for tax in fposition_id.tax_ids:
|
||||
if tax.tax_src_id.id == t.id:
|
||||
if tax.tax_dest_id:
|
||||
result.append(tax.tax_dest_id.id)
|
||||
ok=True
|
||||
|
@ -47,10 +48,10 @@ class account_fiscal_position(osv.osv):
|
|||
result.append(t.id)
|
||||
return result
|
||||
|
||||
def map_account(self, cr, uid, partner, account_id, context={}):
|
||||
if (not partner) or (not partner.property_account_position) :
|
||||
def map_account(self, cr, uid, fposition_id, account_id, context={}):
|
||||
if not fposition_id :
|
||||
return account_id
|
||||
for pos in partner.property_account_position.account_ids:
|
||||
for pos in fposition_id.account_ids:
|
||||
if pos.account_src_id.id==account_id:
|
||||
account_id = pos.account_dest_id.id
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue