48
'discount': fields.float('Discount (%)', digits=(16, 2), help="If you chose apply a discount for this way you will overide the option of calculate based on Price Lists, you will need to change again the product to update based on pricelists, this value must be between 0-100"),
49
'price_unit': fields.float('Real Unit Price', required=True, digits=(16, 4), help="Price that will be used in the rest of accounting cycle"),
50
'price_base': fields.float('Base Unit Price', required=True, digits=(16, 4), help="Price base taken to calc the discount, is an informative price to use it in the rest of the purchase cycle like reference for users"),
48
'discount': fields.float('Discount (%)', digits=(16, 2), help="""If you
49
chose apply a discount for this way you will
50
overide the option of calculate based on
51
Price Lists, you will need to change again
52
the product to update based on pricelists,
53
this value must be between 0-100"""),
54
'price_unit': fields.float('Real Unit Price', required=True,
55
digits=(16, 4), help="""Price that will be
58
'price_base': fields.float('Base Unit Price', required=True,
59
digits=(16, 4), help="""Price base taken to
65
reference for users"""),
53
68
'discount': lambda *a: 0.0,
56
def discount_change(self, cr, uid, ids, product, discount, price_unit, product_qty, partner_id, price_base):
71
def discount_change(self, cr, uid, ids, product, discount, price_unit,
72
product_qty, partner_id, price_base):
58
74
return {'value': {'price_unit': 0.0, }}
59
75
prod = self.pool.get('product.product').browse(cr, uid, product)
73
89
def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom,
74
partner_id, date_order=False, fiscal_position=False, date_planned=False, name=False, price_unit=False, notes=False):
90
partner_id, date_order=False, fiscal_position=False,
91
date_planned=False, name=False, price_unit=False,
75
93
"""Copied from purchase/purchase.py and modified to take discount"""
77
95
raise osv.except_osv(_('No Pricelist !'), _(
78
'You have to select a pricelist in the purchase form !\nPlease set one before choosing a product.'))
96
'''You have to select a
100
choosing a product.''')
79
102
if not partner_id:
80
raise osv.except_osv(_('No Partner!'), _(
81
'You have to select a partner in the purchase form !\nPlease set one partner before choosing a product.'))
103
raise osv.except_osv(_('No Partner!'), _('''You have to select a
104
partner in the purchase
105
form !\nPlease set one
106
partner before choosing
83
return {'value': {'price_unit': 0.0, 'name': '', 'notes': '', 'product_uom': False}, 'domain': {'product_uom': []}}
109
return {'value': {'price_unit': 0.0,
112
'product_uom': False},
113
'domain': {'product_uom': []}}
84
114
prod = self.pool.get('product.product').browse(cr, uid, product)
117
147
prod_name = prod.partner_ref
120
'value': {'price_unit': price, 'price_base': price, 'name': prod_name, 'taxes_id': map(lambda x: x.id, prod.supplier_taxes_id),
121
'date_planned': dt, 'notes': prod.description_purchase,
150
'value': {'price_unit': price,
153
'taxes_id': map(lambda x: x.id, prod.supplier_taxes_id),
155
'notes': prod.description_purchase,
126
160
partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
127
161
taxes = self.pool.get('account.tax').browse(
128
162
cr, uid, map(lambda x: x.id, prod.supplier_taxes_id))
129
163
fpos = fiscal_position and self.pool.get(
130
'account.fiscal.position').browse(cr, uid, fiscal_position) or False
164
'account.fiscal.position').browse(cr, uid, fiscal_position) or \
131
166
res['value']['taxes_id'] = self.pool.get(
132
167
'account.fiscal.position').map_tax(cr, uid, fpos, taxes)
137
172
domain = {'product_uom': [(
138
173
'category_id', '=', res2[0]['category_id'][0])]}
139
174
if res2[0]['category_id'][0] != res3:
140
raise osv.except_osv(_('Wrong Product UOM !'), _(
141
'You have to select a product UOM in the same category than the purchase UOM of the product'))
175
raise osv.except_osv(_('Wrong Product UOM !'), _('''You have to
143
182
res['domain'] = domain
148
186
class purchase_order(osv.Model):
149
187
_name = "purchase.order"
150
188
_inherit = "purchase.order"
152
190
def _get_order(self, cr, uid, ids, context={}):
153
191
"""Copied from purchase/purchase.py"""
155
for line in self.pool.get('purchase.order.line').browse(cr, uid, ids, context=context):
193
for line in self.pool.get('purchase.order.line').browse(cr, uid,
156
195
result[line.order_id.id] = True
157
196
return result.keys()
197
'price_wd': fields.function(_get_price_wd, method=True, string='Price With Discount', store=True, type="float", digits=(16, 4)),
234
'price_wd': fields.function(_get_price_wd, method=True,
235
string='Price With Discount',
236
store=True, type="float", digits=(16, 4)),
199
238
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: