ACCOUNT, ACCOUNT_TAX_INCLUDE, PURCHASE, PURCHASE_TAX_INCLUDE, SALE_TAX_INCLUDE: fix tax include
bzr revid: ced-1bbd054ee49127bcd6018da41a9657c389ca9a51
This commit is contained in:
parent
655ee8cf3d
commit
0427cff53f
|
@ -784,14 +784,14 @@ class account_invoice_tax(osv.osv):
|
|||
cur = inv.currency_id
|
||||
|
||||
for line in inv.invoice_line:
|
||||
for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_unit, line.quantity, inv.address_invoice_id.id, line.product_id, inv.partner_id):
|
||||
for tax in tax_obj.compute(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):
|
||||
val={}
|
||||
val['invoice_id'] = inv.id
|
||||
val['name'] = tax['name']
|
||||
val['amount'] = cur_obj.round(cr, uid, cur, tax['amount'])
|
||||
val['manual'] = False
|
||||
val['sequence'] = tax['sequence']
|
||||
val['base'] = tax['price_unit'] * line['quantity']
|
||||
val['base'] = tax['price_unit'] * line['quantity'] * (1-(line.discount or 0.0)/100.0)
|
||||
|
||||
if inv.type in ('out_invoice','in_invoice'):
|
||||
val['base_code_id'] = tax['base_code_id']
|
||||
|
|
|
@ -68,8 +68,8 @@ class account_invoice(osv.osv):
|
|||
'Price method', required=True, readonly=True,
|
||||
states={'draft':[('readonly',False)]}),
|
||||
'amount_untaxed': fields.function(_amount_untaxed, digits=(16,2), method=True,string='Untaxed Amount'),
|
||||
'amount_tax': fields.function(_amount_tax, method=True, string='Tax'),
|
||||
'amount_total': fields.function(_amount_total, method=True, string='Total'),
|
||||
'amount_tax': fields.function(_amount_tax, method=True, string='Tax', store=True),
|
||||
'amount_total': fields.function(_amount_total, method=True, string='Total', store=True),
|
||||
}
|
||||
_defaults = {
|
||||
'price_type': lambda *a: 'tax_excluded',
|
||||
|
@ -88,22 +88,32 @@ class account_invoice_line(osv.osv):
|
|||
res2 = res.copy()
|
||||
for line in self.browse(cr, uid, ids):
|
||||
if line.invoice_id.price_type == 'tax_included':
|
||||
product_taxes = None
|
||||
if line.product_id:
|
||||
for tax in tax_obj.compute_inv(cr, uid,line.product_id.taxes_id, line.price_unit, line.quantity):
|
||||
if line.invoice_id.type in ('out_invoice', 'out_refund'):
|
||||
product_taxes = line.product_id.taxes_id
|
||||
else:
|
||||
product_taxes = line.product_id.supplier_taxes_id
|
||||
if product_taxes:
|
||||
for tax in tax_obj.compute_inv(cr, uid, product_taxes, res[line.id]/line.quantity, line.quantity):
|
||||
res[line.id] = res[line.id] - tax['amount']
|
||||
else:
|
||||
for tax in tax_obj.compute_inv(cr, uid,line.invoice_line_tax_id, line.price_unit, line.quantity):
|
||||
for tax in tax_obj.compute_inv(cr, uid,line.invoice_line_tax_id, res[line.id]/line.quantity, line.quantity):
|
||||
res[line.id] = res[line.id] - tax['amount']
|
||||
if name == 'price_subtotal_incl':
|
||||
if line.product_id and line.invoice_id.price_type == 'tax_included':
|
||||
prod_taxe_ids = [ t.id for t in line.product_id.taxes_id ]
|
||||
if name == 'price_subtotal_incl' and line.invoice_id.price_type == 'tax_included':
|
||||
prod_taxe_ids = None
|
||||
line_taxe_ids = None
|
||||
if product_taxes:
|
||||
prod_taxe_ids = [ t.id for t in product_taxes ]
|
||||
prod_taxe_ids.sort()
|
||||
line_taxe_ids = [ t.id for t in line.invoice_line_tax_id ]
|
||||
line_taxe_ids.sort()
|
||||
if line.product_id and line.invoice_id.price_type == 'tax_included' and prod_taxe_ids == line_taxe_ids:
|
||||
if product_taxes and prod_taxe_ids == line_taxe_ids:
|
||||
res[line.id] = res2[line.id]
|
||||
elif not line.product_id:
|
||||
res[line.id] = res2[line.id]
|
||||
else:
|
||||
for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_unit, line.quantity):
|
||||
for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, res[line.id]/line.quantity, line.quantity):
|
||||
res[line.id] = res[line.id] + tax['amount']
|
||||
res[line.id]= round(res[line.id], 2)
|
||||
return res
|
||||
|
@ -193,7 +203,7 @@ class account_invoice_tax(osv.osv):
|
|||
return super(account_invoice_tax,self).compute(cr, uid, invoice_id)
|
||||
|
||||
for line in inv.invoice_line:
|
||||
for tax in tax_obj.compute_inv(cr, uid, line.invoice_line_tax_id, line.price_unit, line.quantity, inv.address_invoice_id.id, line.product_id, inv.partner_id):
|
||||
for tax in tax_obj.compute_inv(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):
|
||||
val={}
|
||||
val['invoice_id'] = inv.id
|
||||
val['name'] = tax['name']
|
||||
|
|
|
@ -48,14 +48,15 @@ class purchase_order(osv.osv):
|
|||
return res
|
||||
|
||||
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
|
||||
id_set = ",".join(map(str, ids))
|
||||
cr.execute("SELECT s.id,COALESCE(SUM(l.price_unit*l.product_qty),0) AS amount FROM purchase_order s LEFT OUTER JOIN purchase_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id ")
|
||||
res = dict(cr.fetchall())
|
||||
res = {}
|
||||
cur_obj=self.pool.get('res.currency')
|
||||
for id in res.keys():
|
||||
order=self.browse(cr, uid, [id])[0]
|
||||
cur=order.pricelist_id.currency_id
|
||||
res[id]=cur_obj.round(cr, uid, cur, res[id])
|
||||
for purchase in self.browse(cr, uid, ids):
|
||||
res[purchase.id] = 0.0
|
||||
for line in purchase.order_line:
|
||||
res[purchase.id] += line.price_subtotal
|
||||
cur = purchase.pricelist_id.currency_id
|
||||
res[purchase.id] = cur_obj.round(cr, uid, cur, res[purchase.id])
|
||||
|
||||
return res
|
||||
|
||||
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
||||
|
|
|
@ -34,20 +34,7 @@ from osv import fields, osv
|
|||
import ir
|
||||
|
||||
class purchase_order(osv.osv):
|
||||
def _amount_untaxed(self, cr, uid, ids, prop, unknow_none,unknow_dict):
|
||||
ti = []
|
||||
for inv in self.read(cr, uid, ids, ['price_type']):
|
||||
if inv['price_type']=='tax_included':
|
||||
ti.append(inv['id'])
|
||||
id_set=",".join(map(str,ids))
|
||||
cr.execute("SELECT s.id,COALESCE(SUM(l.price_unit*l.product_qty),0)::decimal(16,2) AS amount FROM purchase_order s LEFT OUTER JOIN purchase_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id ")
|
||||
res=dict(cr.fetchall())
|
||||
if len(ti):
|
||||
tax = self._amount_tax(cr, uid, ti, prop, unknow_none,unknow_dict)
|
||||
for id in ti:
|
||||
res[id] = res[id] - tax.get(id, 0.0)
|
||||
return res
|
||||
|
||||
_inherit = "purchase.order"
|
||||
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
||||
res = {}
|
||||
cur_obj=self.pool.get('res.currency')
|
||||
|
@ -63,13 +50,11 @@ class purchase_order(osv.osv):
|
|||
val += cur_obj.round(cr, uid, cur, c['amount'])
|
||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||
return res
|
||||
_inherit = "purchase.order"
|
||||
_columns = {
|
||||
'price_type': fields.selection([
|
||||
('tax_included','Tax included'),
|
||||
('tax_excluded','Tax excluded')
|
||||
], 'Price method', required=True),
|
||||
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
|
||||
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
|
||||
}
|
||||
_defaults = {
|
||||
|
@ -81,3 +66,40 @@ class purchase_order(osv.osv):
|
|||
}
|
||||
purchase_order()
|
||||
|
||||
class purchase_order_line(osv.osv):
|
||||
_inherit = 'purchase.order.line'
|
||||
def _amount_line(self, cr, uid, ids, name, arg, context):
|
||||
res = {}
|
||||
cur_obj=self.pool.get('res.currency')
|
||||
tax_obj = self.pool.get('account.tax')
|
||||
res = super(purchase_order_line, self)._amount_line(cr, uid, ids, name, arg, context)
|
||||
res2 = res.copy()
|
||||
for line in self.browse(cr, uid, ids):
|
||||
if line.order_id.price_type == 'tax_included':
|
||||
if line.product_id:
|
||||
for tax in tax_obj.compute_inv(cr, uid, line.product_id.supplier_taxes_id, res[line.id]/line.product_qty, line.product_qty):
|
||||
res[line.id] = res[line.id] - tax['amount']
|
||||
else:
|
||||
for tax in tax_obj.compute_inv(cr, uid, line.taxes_id, res[line.id]/line.product_qty, line.product_qty):
|
||||
res[line.id] = res[line.id] - tax['amount']
|
||||
if name == 'price_subtotal_incl' and line.order_id.price_type == 'tax_included':
|
||||
if line.product_id:
|
||||
prod_taxe_ids = [ t.id for t in line.product_id.supplier_taxes_id ]
|
||||
prod_taxe_ids.sort()
|
||||
line_taxe_ids = [ t.id for t in line.taxes_id ]
|
||||
line_taxe_ids.sort()
|
||||
if line.product_id and prod_taxe_ids == line_taxe_ids:
|
||||
res[line.id] = res2[line.id]
|
||||
elif not line.product_id:
|
||||
res[line.id] = res2[line.id]
|
||||
else:
|
||||
for tax in tax_obj.compute(cr, uid, line.taxes_id, res[line.id]/line.product_qty, line.product_qty):
|
||||
res[line.id] = res[line.id] + tax['amount']
|
||||
cur = line.order_id.pricelist_id.currency_id
|
||||
res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
|
||||
return res
|
||||
_columns = {
|
||||
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal w/o tax'),
|
||||
'price_subtotal_incl': fields.function(_amount_line, method=True, string='Subtotal'),
|
||||
}
|
||||
purchase_order_line()
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="account_tax_view_price_subtotal_incl">
|
||||
<field name="name">purchase.order.line.tree</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="model">purchase.order.line</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_line_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="price_subtotal" position="after">
|
||||
<field name="price_subtotal_incl"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
|
||||
|
|
|
@ -34,20 +34,7 @@ from osv import fields, osv
|
|||
import ir
|
||||
|
||||
class sale_order(osv.osv):
|
||||
def _amount_untaxed(self, cr, uid, ids, prop, unknow_none,unknow_dict):
|
||||
ti = []
|
||||
for inv in self.read(cr, uid, ids, ['price_type']):
|
||||
if inv['price_type']=='tax_included':
|
||||
ti.append(inv['id'])
|
||||
id_set=",".join(map(str,ids))
|
||||
cr.execute("SELECT s.id,COALESCE(SUM(l.price_unit*l.product_uos_qty*(100.0-l.discount))/100.0,0)::decimal(16,2) AS amount FROM sale_order s LEFT OUTER JOIN sale_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id ")
|
||||
res=dict(cr.fetchall())
|
||||
if len(ti):
|
||||
tax = self._amount_tax(cr, uid, ti, prop, unknow_none,unknow_dict)
|
||||
for id in ti:
|
||||
res[id] = res[id] - tax.get(id,0.0)
|
||||
return res
|
||||
|
||||
_inherit = "sale.order"
|
||||
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
||||
res = {}
|
||||
cur_obj=self.pool.get('res.currency')
|
||||
|
@ -63,13 +50,11 @@ class sale_order(osv.osv):
|
|||
val += cur_obj.round(cr, uid, cur, c['amount'])
|
||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||
return res
|
||||
_inherit = "sale.order"
|
||||
_columns = {
|
||||
'price_type': fields.selection([
|
||||
('tax_included','Tax included'),
|
||||
('tax_excluded','Tax excluded')
|
||||
], 'Price method', required=True),
|
||||
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
|
||||
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
|
||||
}
|
||||
_defaults = {
|
||||
|
@ -81,3 +66,45 @@ class sale_order(osv.osv):
|
|||
}
|
||||
sale_order()
|
||||
|
||||
class sale_order_line(osv.osv):
|
||||
_inherit = "sale.order.line"
|
||||
def _amount_line(self, cr, uid, ids, name, arg, context):
|
||||
res = {}
|
||||
cur_obj=self.pool.get('res.currency')
|
||||
tax_obj = self.pool.get('account.tax')
|
||||
res = super(sale_order_line, self)._amount_line(cr, uid, ids, name, arg, context)
|
||||
res2 = res.copy()
|
||||
for line in self.browse(cr, uid, ids):
|
||||
if line.product_uos.id:
|
||||
qty = line.product_uos_qty
|
||||
else:
|
||||
qty = line.product_uom_qty
|
||||
if line.order_id.price_type == 'tax_included':
|
||||
if line.product_id:
|
||||
for tax in tax_obj.compute_inv(cr, uid, line.product_id.taxes_id, res[line.id]/qty, qty):
|
||||
res[line.id] = res[line.id] - tax['amount']
|
||||
else:
|
||||
for tax in tax_obj.compute_inv(cr, uid, line.tax_id, res[line.id]/qty, qty):
|
||||
res[line.id] = res[line.id] - tax['amount']
|
||||
if name == 'price_subtotal_incl' and line.order_id.price_type == 'tax_included':
|
||||
if line.product_id:
|
||||
prod_taxe_ids = [ t.id for t in line.product_id.taxes_id ]
|
||||
prod_taxe_ids.sort()
|
||||
line_taxe_ids = [ t.id for t in line.tax_id ]
|
||||
line_taxe_ids.sort()
|
||||
if line.product_id and prod_taxe_ids == line_taxe_ids:
|
||||
res[line.id] = res2[line.id]
|
||||
elif not line.product_id:
|
||||
res[line.id] = res2[line.id]
|
||||
else:
|
||||
for tax in tax_obj.compute(cr, uid, line.tax_id, res[line.id]/qty, qty):
|
||||
res[line.id] = res[line.id] + tax['amount']
|
||||
cur = line.order_id.pricelist_id.currency_id
|
||||
res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
|
||||
return res
|
||||
_columns = {
|
||||
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal w/o tax'),
|
||||
'price_subtotal_incl': fields.function(_amount_line, method=True, string='Subtotal'),
|
||||
}
|
||||
sale_order_line()
|
||||
|
||||
|
|
|
@ -13,6 +13,17 @@
|
|||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="account_tax_view_subtotal_incl">
|
||||
<field name="name">sale.order.exlcuded.view.form</field>
|
||||
<field name="type">form</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="price_subtotal" position="after">
|
||||
<field name="price_subtotal_incl"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
|
|
Loading…
Reference in New Issue