Add product's cost price to plan form, add confirmation message

This commit is contained in:
Guillem Barba 2015-02-06 09:52:05 +01:00
parent 7affa7ac0d
commit 51a27e2140
3 changed files with 20 additions and 11 deletions

16
plan.py
View file

@ -67,6 +67,9 @@ class Plan(ModelSQL, ModelView):
digits=(16, DIGITS)),
'get_products_cost')
costs = fields.One2Many('product.cost.plan.cost', 'plan', 'Costs')
product_cost_price = fields.Function(fields.Numeric('Product Cost Price',
digits=(16, DIGITS)),
'get_product_cost_price')
cost_price = fields.Function(fields.Numeric('Unit Cost Price',
digits=(16, DIGITS)),
'get_cost_price')
@ -79,7 +82,7 @@ class Plan(ModelSQL, ModelView):
'compute': {
'icon': 'tryton-spreadsheet',
},
'update_product_prices': {
'update_product_cost_price': {
'icon': 'tryton-refresh',
},
})
@ -196,6 +199,9 @@ class Plan(ModelSQL, ModelView):
digits = self.__class__.products_cost.digits[1]
return cost.quantize(Decimal(str(10 ** -digits)))
def get_product_cost_price(self, name):
return self.product.cost_price if self.product else None
def get_cost_price(self, name):
return sum(c.cost for c in self.costs if c.cost)
@ -323,15 +329,15 @@ class Plan(ModelSQL, ModelView):
@classmethod
@ModelView.button
def update_product_prices(cls, plans):
def update_product_cost_price(cls, plans):
for plan in plans:
if not plan.product:
continue
plan._update_product_prices()
plan._update_product_cost_price()
plan.product.save()
plan.product.template.save()
def _update_product_prices(self):
def _update_product_cost_price(self):
pool = Pool()
Uom = pool.get('product.uom')
@ -366,8 +372,8 @@ class Plan(ModelSQL, ModelView):
self.bom = bom
self.save()
ProductBOM()
if self.product.boms:
# TODO: create new bom to allow diferent "versions"?
product_bom = self.product.boms[0]
if product_bom.bom:
self.raise_user_warning('product_already_has_bom%s' % self.id,

View file

@ -101,13 +101,13 @@
<field name="group" ref="group_product_cost_plan"/>
</record>
<record model="ir.model.button" id="plan_update_product_prices_button">
<field name="name">update_product_prices</field>
<record model="ir.model.button" id="plan_update_product_cost_price_button">
<field name="name">update_product_cost_price</field>
<field name="model" search="[('model', '=', 'product.cost.plan')]"/>
</record>
<record model="ir.model.button-res.group"
id="plan_update_product_prices_button_group_product_admin">
<field name="button" ref="plan_compute_button"/>
id="plan_update_product_cost_price_button_group_product_admin">
<field name="button" ref="plan_update_product_cost_price_button"/>
<field name="group" ref="product.group_product_admin"/>
</record>

View file

@ -36,6 +36,9 @@
</notebook>
<label name="cost_price"/>
<field name="cost_price"/>
<button name="update_product_prices" string="Update Product's Prices"
colspan="2"/>
<label name="product_cost_price"/>
<field name="product_cost_price"/>
<button name="update_product_cost_price"
string="Update Product's Cost Price" colspan="2"
confirm="It will modify the product's field loosing the current value. Are you sure?"/>
</form>