1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
class account_invoice(osv.osv):
_inherit = 'account.invoice'
_columns = {
'subject': fields.text('Subject',size=300,required=True,translate=True),
'reference': fields.text('Reference',size=300,required=True,translate=True),
'greetings': fields.selection((('Avec nos remerciements.','Avec nos remerciements.'),('Thanking you for your consideration.','Thanking you for your consideration.'), ('Vide',' '), (u'La livraison sera effectuée après la réception de votre paiement. Avec nos remerciements.','La livraison sera effectuée après la réception de votre paiement. Avec nos remerciements.'), (u'The delivery will be done after the reception of your payment. Thanking you for your consideration.','The delivery will be done after the reception of your payment. Thanking you for your consideration.')), 'Salutations', required=True),
'contact': fields.many2one('res.users', 'Further inquiries',readonly=True, track_visibility='always', states={'draft':[('readonly',False)]}),
'contacts': fields.many2one('res.partner','Contacts'),
'company_contact': fields.many2one('res.partner', 'Contact'),
}
account_invoice()
class account_invoice_line(osv.osv):
_inherit = 'account.invoice.line'
# ajout des champs Poid et poid total
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'),
}
# Code qui marche pas
def _amount_weight(self, cr, uid, ids, name, args, context=None):
tot= {}
for invoice in self.browse(cr, uid, ids, context=context):
tot[invoice.id] = {
'amount_weight': 0.0,
}
for line in invoice.invoice_line:
tot[invoice.id]['amount_weight'] += line.weight
return tot
_columns={
'weight_tot_weight':fields.function(_amount_weight, type='float', string='Poids Total'),
}
# 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() |
Partager