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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
import logging
_logger = logging.getLogger(__name__)
from openerp.osv import fields, osv
class product_product(osv.osv):
_name = 'product.product'
_inherit = "product.product" # qui herite elle meme de product.template
def _ttc_calc2(self, cr, uid, ids, name, value, args, context=None):
if context is None:
context = {}
#_logger.info('ids : %r', ids)
res = {}
for obj in self.browse(cr,uid,ids,context=context):
if obj.taxes_id:
#_logger.info('obj : %r', obj.taxes_id)
obj_tax = self.pool.get('account.tax')
# permet de récupérer la company_id du user
obj_user = self.pool.get('res.users')
user = obj_user.browse(cr, uid, uid)
cr.execute('SELECT tax_id FROM product_taxes_rel WHERE prod_id = %s',(obj.id,))
sql = cr.fetchone()
#_logger.info('sql : %r', sql)
# ici on récupère les taxes pour la company de l'utilisateur
#taxes_ids = obj_tax.search(cr, uid, [('id', 'in', obj.taxes_id), ('company_id', '=', user.company_id.id)])
taxes_ids = obj_tax.search(cr, uid, [('id', 'in', sql), ('company_id', '=', user.company_id.id)])
if taxes_ids:
# ici on récupère les valeurs de la 1ere taxe
tax = obj_tax.browse(cr, uid, taxes_ids[0])
tax_amount = tax.amount
tax_type = tax.type
tax_include = tax.price_include
#_logger.info('TI : %r', tax_include)
# le prix du produit
p_price = obj.lst_price
if tax_type == 'percent':
if tax_include==False:
res[obj.id] = p_price + (p_price * tax_amount)
else:
res[obj.id] = p_price / (1 + tax_amount)
else:
if tax_include==False:
res[obj.id] = p_price + tax_amount
else:
res[obj.id] = p_price - tax_amount
return res
def _amount2(self,cr,uid,ids,field,arg,context=None):
if context is None:
context = {}
res2 = {}
for obj in self.browse(cr,uid,ids,context=context):
obj_tax = self.pool.get('account.tax')
# permet de récupérer la company_id du user
obj_user = self.pool.get('res.users')
user = obj_user.browse(cr, uid, uid)
cr.execute('SELECT tax_id FROM product_taxes_rel WHERE prod_id = %s',(obj.id,))
sql = cr.fetchone()
taxes_ids = obj_tax.search(cr, uid, [('id', 'in', sql), ('company_id', '=', user.company_id.id)])
if taxes_ids:
# ici on récupère les valeurs de la 1ere taxe
tax = obj_tax.browse(cr, uid, taxes_ids[0])
tax_amount = tax.amount*100
tax_type = tax.type
if tax.price_include == False:
tax_include = 'not include'
else:
tax_include = 'include'
res2[obj.id] = str(tax_amount) + '% - ' + tax_include
return res2
_columns = {
'price_ttc': fields.function(_ttc_calc2, string='Ttc/Ht', type='float'),
'taux_tax': fields.function(_amount2, string='Taxes', type='char'),
}
product_product() |
Partager