mrp_average_cost: Fix decimal precision

product_usability: add link to show history of standard price
This commit is contained in:
Alexis de Lattre
2017-05-22 20:57:33 +02:00
parent 08445ad370
commit b8255a5287
4 changed files with 56 additions and 34 deletions

View File

@@ -18,9 +18,8 @@ class LabourCostProfile(models.Model):
name = fields.Char( name = fields.Char(
string='Name', required=True, track_visibility='onchange') string='Name', required=True, track_visibility='onchange')
hour_cost = fields.Monetary( hour_cost = fields.Float(
string='Cost per Hour', required=True, string='Cost per Hour', required=True,
currency_field='company_currency_id',
digits=dp.get_precision('Product Price'), digits=dp.get_precision('Product Price'),
track_visibility='onchange', track_visibility='onchange',
help="Labour cost per hour per person in company currency") help="Labour cost per hour per person in company currency")
@@ -54,9 +53,9 @@ class MrpBomLabourLine(models.Model):
"items of the BOM, in hours.") "items of the BOM, in hours.")
labour_cost_profile_id = fields.Many2one( labour_cost_profile_id = fields.Many2one(
'labour.cost.profile', string='Labour Cost Profile', required=True) 'labour.cost.profile', string='Labour Cost Profile', required=True)
labour_cost_subtotal = fields.Monetary( labour_cost_subtotal = fields.Float(
compute='_compute_labour_cost_subtotal', readonly=True, store=True, compute='_compute_labour_cost_subtotal', readonly=True, store=True,
string='Subtotal', currency_field='company_currency_id') digits=dp.get_precision('Product Price'), string='Subtotal')
company_currency_id = fields.Many2one( company_currency_id = fields.Many2one(
related='bom_id.company_id.currency_id', readonly=True, related='bom_id.company_id.currency_id', readonly=True,
string='Company Currency') string='Company Currency')
@@ -107,28 +106,24 @@ class MrpBom(models.Model):
company_currency_id = fields.Many2one( company_currency_id = fields.Many2one(
related='company_id.currency_id', readonly=True, related='company_id.currency_id', readonly=True,
string='Company Currency') string='Company Currency')
total_labour_cost = fields.Monetary( total_labour_cost = fields.Float(
compute='_compute_total_labour_cost', readonly=True, compute='_compute_total_labour_cost', readonly=True,
currency_field='company_currency_id',
digits=dp.get_precision('Product Price'), digits=dp.get_precision('Product Price'),
string="Total Labour Cost") string="Total Labour Cost")
extra_cost = fields.Monetary( extra_cost = fields.Float(
string='Extra Cost', track_visibility='onchange', string='Extra Cost', track_visibility='onchange',
digits=dp.get_precision('Product Price'), digits=dp.get_precision('Product Price'),
currency_field='company_currency_id',
help="Extra cost for the production of the quantity of " help="Extra cost for the production of the quantity of "
"items of the BOM, in company currency. " "items of the BOM, in company currency. "
"You can use this field to enter the cost of the consumables " "You can use this field to enter the cost of the consumables "
"that are used to produce the product but are not listed in " "that are used to produce the product but are not listed in "
"the BOM") "the BOM")
total_components_cost = fields.Monetary( total_components_cost = fields.Float(
compute='_compute_total_cost', readonly=True, compute='_compute_total_cost', readonly=True,
currency_field='company_currency_id',
digits=dp.get_precision('Product Price'), digits=dp.get_precision('Product Price'),
string='Total Components Cost') string='Total Components Cost')
total_cost = fields.Float( total_cost = fields.Float(
compute='_compute_total_cost', readonly=True, compute='_compute_total_cost', readonly=True, string='Total Cost',
currency_field='company_currency_id', string='Total Cost',
digits=dp.get_precision('Product Price'), digits=dp.get_precision('Product Price'),
help="Total Cost = Total Components Cost + " help="Total Cost = Total Components Cost + "
"Total Labour Cost + Extra Cost") "Total Labour Cost + Extra Cost")
@@ -170,16 +165,16 @@ class MrpBomLine(models.Model):
standard_price = fields.Float( standard_price = fields.Float(
related='product_id.standard_price', readonly=True) related='product_id.standard_price', readonly=True)
# Monetary ? standard_price on product is a float... company_currency_id = fields.Many2one(
# company_currency_id = related='bom_id.company_id.currency_id', readonly=True,
string='Company Currency')
class MrpProduction(models.Model): class MrpProduction(models.Model):
_inherit = 'mrp.production' _inherit = 'mrp.production'
unit_cost = fields.Monetary( unit_cost = fields.Float(
string='Unit Cost', readonly=True, string='Unit Cost', readonly=True,
currency_field='company_currency_id',
digits=dp.get_precision('Product Price'), digits=dp.get_precision('Product Price'),
help="This cost per unit in the unit of measure of the product " help="This cost per unit in the unit of measure of the product "
"in company currency takes into account " "in company currency takes into account "

View File

@@ -12,10 +12,10 @@
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/> <field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="routing_id" position="after"> <field name="routing_id" position="after">
<field name="total_components_cost"/> <field name="total_components_cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="total_labour_cost"/> <field name="total_labour_cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="extra_cost"/> <field name="extra_cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<label for="total_cost"/> <label for="total_cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<div> <div>
<field name="total_cost" widget="monetary" <field name="total_cost" widget="monetary"
options="{'currency_field': 'company_currency_id'}" options="{'currency_field': 'company_currency_id'}"
@@ -33,7 +33,8 @@
</page> </page>
</xpath> </xpath>
<xpath expr="//field[@name='bom_line_ids']/tree/field[@name='product_uom_id']" position="after"> <xpath expr="//field[@name='bom_line_ids']/tree/field[@name='product_uom_id']" position="after">
<field name="standard_price"/> <field name="standard_price" widget="monetary" options="{'currency_field': 'company_currency_id'}" sum="Total"/>
<field name="company_currency_id" invisible="1"/>
</xpath> </xpath>
</field> </field>
</record> </record>
@@ -46,7 +47,7 @@
<field name="bom_id" invisible="not context.get('mrp_bom_labour_line_main_view')"/> <field name="bom_id" invisible="not context.get('mrp_bom_labour_line_main_view')"/>
<field name="labour_time" string="Labour Time (hours)"/> <field name="labour_time" string="Labour Time (hours)"/>
<field name="labour_cost_profile_id"/> <field name="labour_cost_profile_id"/>
<field name="labour_cost_subtotal" sum="Total"/> <field name="labour_cost_subtotal" sum="Total" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
<field name="note"/> <field name="note"/>
</tree> </tree>
@@ -66,7 +67,7 @@
<label string="hours"/> <label string="hours"/>
</div> </div>
<field name="labour_cost_profile_id"/> <field name="labour_cost_profile_id"/>
<field name="labour_cost_subtotal"/> <field name="labour_cost_subtotal" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
<field name="note"/> <field name="note"/>
</group> </group>
@@ -83,7 +84,7 @@
<form string="Labour Cost Profile"> <form string="Labour Cost Profile">
<group name="main"> <group name="main">
<field name="name"/> <field name="name"/>
<field name="hour_cost"/> <field name="hour_cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="company_id" groups="base.group_multi_company"/> <field name="company_id" groups="base.group_multi_company"/>
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
</group> </group>
@@ -97,7 +98,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Labour Cost Profiles"> <tree string="Labour Cost Profiles">
<field name="name"/> <field name="name"/>
<field name="hour_cost"/> <field name="hour_cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
</tree> </tree>
</field> </field>

View File

@@ -16,6 +16,17 @@ class ProductTemplate(models.Model):
purchase_ok = fields.Boolean(track_visibility='onchange') purchase_ok = fields.Boolean(track_visibility='onchange')
active = fields.Boolean(track_visibility='onchange') active = fields.Boolean(track_visibility='onchange')
def show_product_price_history(self):
self.ensure_one()
products = self.env['product.product'].search(
[('product_tmpl_id', '=', self._context['active_id'])])
action = self.env['ir.actions.act_window'].for_xml_id(
'product_usability', 'product_price_history_action')
action.update({
'domain': "[('id', 'in', %s)]" % products.ids,
})
return action
class ProductProduct(models.Model): class ProductProduct(models.Model):
_inherit = 'product.product' _inherit = 'product.product'
@@ -38,9 +49,26 @@ class ProductProduct(models.Model):
'unique(default_code)', 'unique(default_code)',
'This internal reference already exists!')] 'This internal reference already exists!')]
def show_product_price_history(self):
self.ensure_one()
action = self.env['ir.actions.act_window'].for_xml_id(
'product_usability', 'product_price_history_action')
action.update({
'domain': "[('product_id', '=', %d)]" % self.ids[0],
})
return action
class ProductSupplierinfo(models.Model): class ProductSupplierinfo(models.Model):
_inherit = 'product.supplierinfo' _inherit = 'product.supplierinfo'
name = fields.Many2one( name = fields.Many2one(
domain=[('supplier', '=', True), ('parent_id', '=', False)]) domain=[('supplier', '=', True), ('parent_id', '=', False)])
class ProductPriceHistory(models.Model):
_inherit = 'product.price.history'
company_currency_id = fields.Many2one(
related='company_id.currency_id', readonly=True,
string='Company Currency')

View File

@@ -16,8 +16,9 @@
<group name="main"> <group name="main">
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/> <field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/> <field name="datetime"/>
<field name="cost"/> <field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="company_id" groups="base.group_multi_company"/> <field name="company_id" groups="base.group_multi_company"/>
<field name="company_currency_id" invisible="1"/>
</group> </group>
</form> </form>
</field> </field>
@@ -30,8 +31,9 @@
<tree string="Product Price History" editable="bottom"> <tree string="Product Price History" editable="bottom">
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/> <field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/> <field name="datetime"/>
<field name="cost"/> <field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="company_id" groups="base.group_multi_company"/> <field name="company_id" groups="base.group_multi_company"/>
<field name="company_currency_id" invisible="1"/>
</tree> </tree>
</field> </field>
</record> </record>
@@ -67,13 +69,9 @@
<field name="model">product.template</field> <field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" /> <field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<!-- <field name="standard_price" class="oe_inline" position="after">
<group name="general" position="after"> <button name="show_product_price_history" class="oe_inline oe_link" type="object" string="Show History" context="{'active_id': active_id}"/>
<group name="price_history" string="Price History"> </field>
<field name="price_history_ids" nolabel="1"/>
</group>
</group>
-->
<!-- START for wider 'name' field --> <!-- START for wider 'name' field -->
<!-- Don't make it too big, othesize computers with small resolutions <!-- Don't make it too big, othesize computers with small resolutions
will see the product name + image under the block of buttons --> will see the product name + image under the block of buttons -->