I worked on purchase, for add shipping price value. It works but when I generate the invoice of the purchase. My shipping just disappeared.
I shearch on the modules source code and I don't understand what is the relation between purchase.order and account.invoice. And I don't understand how I can add my shipping value in the invoice.
custom_achat.py
class purchase_order(osv.osv):
_name='purchase.order'
_inherit='purchase.order'
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
res = super(purchase_order, self)._amount_all(cr, uid, ids, field_name, arg, context)
for order in self.browse(cr, uid, ids, context=context):
res[order.id]['amount_total'] += order.frais
return res
def _get_order(self, cr, uid, ids, context=None):
result = {}
for line in self.pool.get('purchase.order.line').browse(cr, uid, ids, context=context):
result[line.order_id.id] = True
return result.keys()
_columns = {
'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The amount without tax", track_visibility='always'),
'amount_tax': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Taxes',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The tax amount"),
'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
store={
'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['frais'], 10),
'purchase.order.line': (_get_order, None, 10),
}, multi="sums",help="The total amount"),
'frais':fields.float('Frais')
}
custom_achat_view.xml
<record model="ir.ui.view" id="purchase_order_form_inherit">
<field name="name">purchase.order.form.inherit</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="amount_untaxed" position="before">
<field name="frais"/>
</field>
</field>
</record>