Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

account.invoice weight SUM function

By
Anne-Sylvie Burri
on 11/19/13, 5:01 AM 1,714 views

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

1

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 11/19/13, 9:14 AM

You have an error here:

    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
        }

it must be:

    res = {}
    # Pour chaque facture
    for invoice in self.browse(cr, uid, ids, context=context):
        # On declare une collection qui contiendra la variable TOTAL
        res[invoice.id] = {
            'weight_total': 0.0
        }

Okay thanks, but i run my openERP serveur but nothing happens .. I have no error but my field is not displayed

J.-M. Burri - Bureau ing.-conseils informatique, Anne-Sylvie Burri
on 11/19/13, 9:36 AM

Do you have eclipse or pycharm installed? They are really useful to debug your code and check what is exactly doing,

GH Mediacloud, Grover Menacho
on 11/19/13, 9:47 AM

No, because my OpenERP server is not in my computer .. it is on a server. But my code seems correct.

J.-M. Burri - Bureau ing.-conseils informatique, Anne-Sylvie Burri
on 11/19/13, 10:30 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 11/19/13, 5:01 AM
Seen: 1714 times
Last updated: 3/16/15, 8:10 AM