Hello,
I am creating a "INVOICE" module that will add attributes to Account.Invoice.
The first step was to make each invoice line is a weight and total weight (weight x quantity) and display it in the invoice line. So far so good here is the code:
class account_invoice_line(osv.osv):
_inherit = 'account.invoice.line'
def _weight_per_line_get_fnc(self, cr, uid, ids, prop, unknow_none, unknow_dict):
res = {}
for line in self.browse(cr, uid, ids):
res[line.id] = line.weight * line.quantity
return res
_columns = {
'weight': fields.float('Poids', help="Le poids du produit."),
'weight_per_line': fields.function(_weight_per_line_get_fnc, type='float', string='Poids par ligne'),
}
# Ici on réécrit la fonction "product_id_change" pour qu'elle remplisse le champ "weight" (créé ci-dessus) avec le poids
# de l'article qui sera sélectionné dans la ligne de commande
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, context=None, company_id=None):
res=super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id=fposition_id, price_unit=price_unit, currency_id=currency_id, context=context, company_id=company_id)
# On va rechercher les données dans la table product_product
context_partner = {'partner_id': partner_id}
product_obj = self.pool.get('product.product')
product_obj = product_obj.browse(cr, uid, product, context=context_partner)
if product_obj.id:
res['value']['weight'] = product_obj.weight_net
return res
account_invoice_line()
My problem is that now I want to display in the invoice (Account.Invoice) the total weight of the invoice lines ..
I take it like this:
from openerp.osv import fields, osv
class account_invoice(osv.osv):
_inherit = 'account.invoice'
def _weight_all(self, cr, uid, ids, name, args, context=None):
res = {}
# Pour chaque facture
for invoice in self.browse(cr, uid, ids, context=context):0
# On declare une collection qui contiendra la variable TOTAL
res[invoice.id] = {
'weight_total': 0.0
}
# Pour chaque ligne de facture..
for line in invoice.invoice_line:
La varialbe total est incrémenter du poid de la ligne de facture
res[invoice.id]['weight_total'] += line.weight
# for line1 in invoice.tax_line:
# res[invoice.id]['amount_tax'] += line1.amount
# res[invoice.id]['weight_total'] = res[invoice.id]['weight_total']
return res
_columns = {
'weight_total': fields.function(_weight_all, type='float', string='Poids Total'),
}
account_invoice()
But its not working..
Error Message :
File "/opt/openerp/openerp/addons/invoice/invoice.py", line 8 res = {} ^ IndentationError: expected an indented block