-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
573 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
================================================== | ||
Supplier Price in scheduled manufacturing products | ||
================================================== | ||
|
||
Get a production cost based on the purchase price of the scheduled products | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
* Mikel Arregi <mikelarregi@avanzosc.es> | ||
* Ana Juaristi <anajuaristi@avanzosc.es> | ||
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright 2016 Mikel Arregi Etxaniz - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2016 Mikel Arregi Etxaniz - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
{ | ||
"name": "Supplier Price in Scheduled Manufacturing Products", | ||
"version": "11.0.1.0.0", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"mrp", | ||
"mrp_production_editable_scheduled_products", | ||
# "purchase_secondary_unit", | ||
], | ||
"author": "AvanzOSC", | ||
"website": "http://www.avanzosc.es", | ||
"contributors": [ | ||
"Mikel Arregi <mikelarregi@avanzosc.es>", | ||
"Ana Juaristi <anajuaristi@avanzosc.es>", | ||
"Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>", | ||
], | ||
"category": "Manufacturing", | ||
"data": [ | ||
"views/mrp_production_view.xml", | ||
"views/res_config_view.xml", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * mrp_supplier_price | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2018-08-28 15:39+0000\n" | ||
"PO-Revision-Date: 2018-08-28 15:39+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.ui.view,arch_db:mrp_supplier_price.mrp_profit_form | ||
msgid "(update)" | ||
msgstr "(actualizar)" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_commercial_percent | ||
msgid "Commercial percentage" | ||
msgstr "Margen comercial (%)" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_product_line_cost | ||
msgid "Cost" | ||
msgstr "Precio de coste" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,help:mrp_supplier_price.field_mrp_production_product_line_unit_final_cost | ||
msgid "Cost by final product unit." | ||
msgstr "Coste por unidad de producto final." | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_product_line_unit_final_cost | ||
msgid "Final Unit Cost" | ||
msgstr "Coste unitario" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model,name:mrp_supplier_price.model_mrp_production | ||
msgid "Manufacturing Order" | ||
msgstr "Orden de producción" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model,name:mrp_supplier_price.model_mrp_production_product_line | ||
msgid "Production Scheduled Product" | ||
msgstr "Fabricación planificada producto" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_profit_percent | ||
msgid "Profit percentage" | ||
msgstr "Beneficio (%)" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_product_line_subtotal | ||
msgid "Subtotal" | ||
msgstr "Subtotal" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_product_line_supplier_id | ||
msgid "Supplier" | ||
msgstr "Proveedor" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_product_line_supplier_id_domain | ||
msgid "Suppliers Domain" | ||
msgstr "Dominio de proveedores" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.ui.view,arch_db:mrp_supplier_price.mrp_config_settings_unitary | ||
msgid "This will allow you to define if the total of the scheduled product list is computed by unit or not." | ||
msgstr "Marcando este campo los calculos de los totales se realizarán por unidad producida." | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model.fields,field_description:mrp_supplier_price.field_mrp_production_scheduled_total | ||
#: model:ir.ui.view,arch_db:mrp_supplier_price.mrp_supplier_price_tree | ||
msgid "Total" | ||
msgstr "Total" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.ui.view,arch_db:mrp_supplier_price.mrp_supplier_price_tree | ||
msgid "Unit cost" | ||
msgstr "Coste por unidad producida" | ||
|
||
#. module: mrp_supplier_price | ||
#: model:ir.model,name:mrp_supplier_price.model_res_config_settings | ||
msgid "res.config.settings" | ||
msgstr "res.config.settings" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2016 Mikel Arregi Etxaniz - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import mrp | ||
from . import res_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# Copyright 2016 Mikel Arregi Etxaniz - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from odoo import api, fields, models | ||
from odoo.addons import decimal_precision as dp | ||
|
||
|
||
class MrpProductionProductLine(models.Model): | ||
_inherit = 'mrp.production.product.line' | ||
|
||
# @api.depends('product_id.uop_coeff', 'product_qty') | ||
# def _compute_uop_qty(self): | ||
# for line in self.filtered('product_id'): | ||
# line.uop_qty = line.product_qty * line.product_id.uop_coeff | ||
|
||
# @api.depends('cost', 'product_id.uop_coeff') | ||
# def _compute_uop_price(self): | ||
# for line in self.filtered('product_id'): | ||
# line.uop_price = line.cost / (line.product_id.uop_coeff or 1.0) | ||
|
||
# @api.depends('product_id.uop_id', 'product_id.uom_po_id') | ||
# def _compute_product_uop(self): | ||
# for line in self.filtered('product_id'): | ||
# line.uop_id = line.product_id.uop_id or line.product_id.uom_po_id | ||
|
||
@api.depends('product_id.seller_ids') | ||
def _compute_variant_suppliers(self): | ||
for line in self.filtered('product_id'): | ||
line.supplier_id_domain = line.product_id.seller_ids.mapped('name') | ||
|
||
supplier_id = fields.Many2one( | ||
comodel_name='res.partner', string='Supplier') | ||
supplier_id_domain = fields.Many2many( | ||
comodel_name='res.partner', compute='_compute_variant_suppliers', | ||
string='Suppliers Domain') | ||
cost = fields.Float( | ||
string='Cost', digits=dp.get_precision('Product Price')) | ||
unit_final_cost = fields.Float( | ||
string='Final Unit Cost', compute='_compute_subtotal', | ||
digits=dp.get_precision('Product Price'), | ||
help='Cost by final product unit.') | ||
subtotal = fields.Float( | ||
string='Subtotal', compute='_compute_subtotal', | ||
digits=dp.get_precision('Product Price')) | ||
# uop_id = fields.Many2one( | ||
# string='Product UoP', comodel_name='product.uom', | ||
# compute='_compute_product_uop') | ||
# uop_qty = fields.Float( | ||
# string='Product UoP Quantity', compute='_compute_uop_qty', | ||
# digits=dp.get_precision('Product Unit of Measure')) | ||
# uop_price = fields.Float( | ||
# string='Purchase Price', compute='_compute_uop_price', | ||
# digits=dp.get_precision('Product Price')) | ||
|
||
def _select_best_cost_price(self, supplier_id=None): | ||
best_price = {} | ||
if supplier_id: | ||
supplier_ids = self.product_id.seller_ids.filtered( | ||
lambda x: x.name == supplier_id) | ||
else: | ||
supplier_ids = self.product_id.seller_ids | ||
for line in supplier_ids.filtered( | ||
lambda l: l.min_qty <= self.product_qty): | ||
if not best_price or line.min_qty <= \ | ||
self.product_qty and \ | ||
best_price['cost'] > line.price: | ||
best_price = {'supplier_id': line.name.id, | ||
'cost': line.price} | ||
return best_price | ||
|
||
@api.depends('cost', 'product_qty', 'production_id', | ||
'production_id.product_qty') | ||
def _compute_subtotal(self): | ||
for line in self: | ||
line.subtotal = line.product_qty * line.cost | ||
line.unit_final_cost = ( | ||
line.subtotal / (line.production_id.product_qty or 1.0)) | ||
|
||
@api.onchange('product_tmpl_id', 'product_id', 'product_qty') | ||
def onchange_product_product_qty(self): | ||
for line in self: | ||
best_supplier = line._select_best_cost_price() | ||
if best_supplier: | ||
line.supplier_id = best_supplier['supplier_id'] | ||
line.cost = best_supplier['cost'] | ||
else: | ||
line.cost = line.product_id.standard_price | ||
|
||
@api.onchange('supplier_id') | ||
def onchange_supplier_id(self): | ||
for line in self: | ||
best_price = line._select_best_cost_price( | ||
supplier_id=line.supplier_id) | ||
if best_price: | ||
line.supplier_id = best_price['supplier_id'] | ||
line.cost = best_price['cost'] | ||
|
||
|
||
class MrpProduction(models.Model): | ||
_inherit = 'mrp.production' | ||
|
||
profit_percent = fields.Float(string='Profit Percentage') | ||
commercial_percent = fields.Float(string='Commercial Percentage') | ||
scheduled_total = fields.Float( | ||
string='Total', compute='_compute_scheduled_total', | ||
digits=dp.get_precision('Product Price')) | ||
production_total = fields.Float( | ||
string='Production Total', compute='_compute_production_total', | ||
digits=dp.get_precision('Product Price')) | ||
|
||
@api.depends('product_lines', 'product_lines.subtotal') | ||
def _compute_scheduled_total(self): | ||
get_param = self.env['ir.config_parameter'].sudo().get_param | ||
by_unit = get_param('mrp.subtotal_by_unit') == 'True' | ||
for mrp in self.filtered(lambda m: m.product_lines and m.product_qty): | ||
subtotal = sum(mrp.mapped('product_lines.subtotal')) | ||
mrp.scheduled_total =\ | ||
subtotal / mrp.product_qty if by_unit else subtotal | ||
|
||
@api.depends('scheduled_total') | ||
def _compute_production_total(self): | ||
get_param = self.env['ir.config_parameter'].sudo().get_param | ||
by_unit = get_param('mrp.subtotal_by_unit') == 'True' | ||
for prod in self: | ||
total = prod.scheduled_total | ||
try: | ||
total += prod.routing_total | ||
except Exception: | ||
pass | ||
prod.production_total =\ | ||
total * (prod.product_qty if by_unit else 1) | ||
|
||
@api.multi | ||
def button_recompute_total(self): | ||
fields_list = ['production_total'] | ||
for field in fields_list: | ||
self.env.add_todo(self._fields[field], self) | ||
self.recompute() | ||
|
||
@api.multi | ||
def _action_compute_lines(self): | ||
res = super(MrpProduction, self)._action_compute_lines() | ||
for line in self.product_lines: | ||
line.onchange_product_product_qty() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2016 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from openerp import api, fields, models | ||
|
||
|
||
class MrpConfigSettings(models.TransientModel): | ||
_inherit = 'res.config.settings' | ||
|
||
subtotal_by_unit = fields.Boolean( | ||
string='Compute unitary total values', | ||
help='This will allow you to define if the total of the scheduled ' | ||
'product list is computed by unit or not.') | ||
|
||
@api.model | ||
def get_values(self): | ||
res = super(MrpConfigSettings, self).get_values() | ||
get_param = self.env['ir.config_parameter'].sudo().get_param | ||
# the value of the parameter is a nonempty string | ||
res.update( | ||
subtotal_by_unit=get_param('mrp.subtotal_by_unit', | ||
'False').lower() == 'true', | ||
) | ||
return res | ||
|
||
@api.multi | ||
def set_values(self): | ||
super(MrpConfigSettings, self).set_values() | ||
set_param = self.env['ir.config_parameter'].sudo().set_param | ||
# we store the repr of the values, since the value of the parameter is | ||
# a required string | ||
set_param('mrp.subtotal_by_unit', repr(self.subtotal_by_unit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2016 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import test_mrp_supplier_price |
Oops, something went wrong.