Hey everybody
Today I'm trying to build my own Odoo templates but I'm stuck on one thing.
So far I managed to get the fields name, product_uom, product_uom_quantity price_unit etc from the model sale.order
But now I need to get the tax amount from the database, which is stored in the model sale.order.line under the field tax_id which is a many2many field.
How exactly can I get the tax_id from the model sale.order.line when I'm using the model sale.order? So far I have the following code:
class sale_order(osv.Model):
_inherit = 'sale.order'
_columns = {
'is_template': fields.boolean('Template'),
'template_id': fields.many2one('sale.order', 'Offer', domain=[('is_template', '=', True)]),
}
def onchange_template(self, cr, uid, ids, template=False, partner_id=False, pricelist_id=False, fiscal_position=False):
line_obj = self.pool.get('sale.order.line')
result = {'order_line': []}
lines = []
if not template:
return {'value': result}
if not partner_id:
raise osv.except_osv(_('No Customer Defined!'), _('Before choosing a template,\n select a customer in the template form.'))
template = self.browse(cr, uid, template)
order_lines = template.order_line
for line in order_lines:
vals = line_obj.product_id_change(cr, uid, [],
pricelist = pricelist_id,
product = line.product_id and line.product_id.id or False,
qty = 0.0,
uom = False,
qty_uos = 0.0,
uos = False,
name = '',
partner_id = partner_id,
lang = False,
update_tax = True,
date_order = False,
packaging = False,
fiscal_position = fiscal_position,
flag = False)
vals['value']['discount'] = line.discount
vals['value']['product_id'] = line.product_id and line.product_id.id or False
vals['value']['name'] = line.name
vals['value']['state'] = 'draft'
vals['value']['product_uom_qty'] = line.product_uom_qty
vals['value']['product_uom'] = line.product_uom and line.product_uom.id or False
vals['value']['price_unit'] = line.price_unit
#vals['value']['tax_id'] = line.tax_id
lines.append(vals['value'])
result['order_line'] = lines
Any information or help is much appreciated!
Yenthe