clearcorp team mailing list archive
-
clearcorp team
-
Mailing list archive
-
Message #00530
lp:~miguel-gutierrez-j/openerp-ccorp-addons/6.1-bom-price-update into lp:openerp-ccorp-addons
Miguel Gutierrez has proposed merging lp:~miguel-gutierrez-j/openerp-ccorp-addons/6.1-bom-price-update into lp:openerp-ccorp-addons.
Requested reviews:
CLEARCORP drivers (clearcorp-drivers)
For more details, see:
https://code.launchpad.net/~miguel-gutierrez-j/openerp-ccorp-addons/6.1-bom-price-update/+merge/143126
--
https://code.launchpad.net/~miguel-gutierrez-j/openerp-ccorp-addons/6.1-bom-price-update/+merge/143126
Your team CLEARCORP development team is subscribed to branch lp:openerp-ccorp-addons.
=== added directory 'bom_price_update'
=== added file 'bom_price_update/__init__.py'
--- bom_price_update/__init__.py 1970-01-01 00:00:00 +0000
+++ bom_price_update/__init__.py 2013-01-14 15:42:24 +0000
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Addons modules by SIESA
+# Copyright (C) 2009-TODAY Soluciones Industriales Electromecanicas S.A. (<http://siesacr.com>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import mrp
=== added file 'bom_price_update/__openerp__.py'
--- bom_price_update/__openerp__.py 1970-01-01 00:00:00 +0000
+++ bom_price_update/__openerp__.py 2013-01-14 15:42:24 +0000
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Addons modules by SIESA
+# Copyright (C) 2009-TODAY Soluciones Industriales Electromecanicas S.A. (<http://siesacr.com>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+{
+ "name" : "MRP Bom Updater",
+ "version" : "1.0",
+ "author" : "SIESA",
+ "category" : "Generic Modules/Inventory Control",
+ "depends" : ["procurement", "stock", "resource", "purchase", "product","process","mrp"],
+ 'complexity': "easy",
+ "website" : "http://www.siesacr.com",
+ "description": """
+ This module update the price of 1 product when BOM is created.
+ """,
+ 'update_xml': [
+
+ ],
+ 'installable': True,
+ 'active': False,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== added file 'bom_price_update/mrp.py'
--- bom_price_update/mrp.py 1970-01-01 00:00:00 +0000
+++ bom_price_update/mrp.py 2013-01-14 15:42:24 +0000
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Addons modules by SIESA
+# Copyright (C) 2009-TODAY Soluciones Industriales Electromecanicas S.A. (<http://siesacr.com>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from osv import osv, fields
+import decimal_precision as dp
+import math
+import logging
+import re
+from tools.translate import _
+
+class mrp_bom(osv.osv):
+ _inherit ='mrp.bom'
+ def create(self, cr, uid, vals, context=None):
+ res = super(mrp_bom, self).create(cr, uid, vals, context)
+ part_obj = self.pool.get('res.partner')
+ bom = self.pool.get('mrp.bom').browse(cr, uid, res, context=context)
+ product = bom.product_id
+ standard_price = 0
+ list_price = 0
+
+ for line in bom.bom_lines:
+ standard_price = standard_price + line.product_id.standard_price * line.product_qty
+ list_price = list_price + line.product_id.list_price * line.product_qty
+ standard_price = standard_price / bom.product_qty
+ list_price = list_price / bom.product_qty
+
+ if standard_price >0 and list_price >0:
+ product.write({'standard_price': standard_price}, context=context)
+ product.write({'list_price': list_price}, context=context)
+
+ return res
+
+ def write(self, cr, uid, ids, vals, context=None):
+ res = super(mrp_bom, self).write(cr, uid, ids, vals, context=context)
+ bom_obj = self.pool.get('mrp.bom')
+ prod_obj = self.pool.get('mrp.production')
+ list_bom = self.pool.get('mrp.bom').browse(cr, uid, ids, context=context)
+ prods_ids = prod_obj.search(cr, uid, [('bom_id','in',ids),('state','in',['confirmed','ready','in_production'])], context=context)
+ standard_price = 0
+ list_price = 0
+
+
+ for bom in list_bom:
+ new_prods = []
+ product = bom.product_id
+
+ for line in bom.bom_lines:
+ standard_price = standard_price + line.product_id.standard_price * line.product_qty
+ list_price = list_price + line.product_id.list_price * line.product_qty
+ standard_price = standard_price / bom.product_qty
+ list_price = list_price / bom.product_qty
+
+ if standard_price >0 and list_price >0:
+ product.write({'standard_price': standard_price}, context=context)
+ product.write({'list_price': list_price}, context=context)
+
+
+ return res
+
+mrp_bom()
=== added directory 'product_search_improver'
=== added file 'product_search_improver/__init__.py'
--- product_search_improver/__init__.py 1970-01-01 00:00:00 +0000
+++ product_search_improver/__init__.py 2013-01-14 15:42:24 +0000
@@ -0,0 +1,1 @@
+import product
=== added file 'product_search_improver/__openerp__.py'
--- product_search_improver/__openerp__.py 1970-01-01 00:00:00 +0000
+++ product_search_improver/__openerp__.py 2013-01-14 15:42:24 +0000
@@ -0,0 +1,25 @@
+
+{
+ "name" : "Products Search Extends",
+ "version" : "1.0",
+ "author" : "SIESA",
+ "category" : "Generic Modules/Inventory Control",
+ "depends" : ["base", "process","product","sale", "decimal_precision","stock"],
+ 'complexity': "easy",
+ "website" : "http://www.siesacr.com",
+ "description": """
+ This module add to product
+ currency_id,
+ part_number,
+ fob_currency_id,
+ cost_fob,
+ and improve the search logic.
+
+ """,
+ 'update_xml': [
+ 'product_view.xml',
+ ],
+ 'installable': True,
+ 'active': False,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== added file 'product_search_improver/product.py'
--- product_search_improver/product.py 1970-01-01 00:00:00 +0000
+++ product_search_improver/product.py 2013-01-14 15:42:24 +0000
@@ -0,0 +1,165 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from osv import osv, fields
+import decimal_precision as dp
+
+import math
+import logging
+import re
+from tools.translate import _
+
+
+class product_product(osv.osv):
+ _inherit = "product.product"
+ def _get_currency(self, cr, uid, ids, prop, unknow_none, unknow_dict):
+ res = {}
+ for order in self.browse(cr, uid, ids):
+ res[order.id] = 0
+ for oline in order.order_line:
+ res[order.id] += oline.price_unit * oline.product_qty
+ return res
+
+ def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
+ res = {}
+ new_args = []
+ cont=0
+
+ if not args:
+ args = []
+ number_params = len(args)
+
+ while cont<number_params:
+ param=args[cont]
+ if ('part_number' in param) or ('default_code' in param) or ('name' in param):
+ search_vals = param[2].split()
+ for val in search_vals:
+ new_args = new_args + [[param[0],'ilike', val]]
+
+ cont = cont +1
+ if len(new_args) > 0:
+ args = new_args
+
+ res = super(product_product, self).search(cr, uid, args, offset, limit, order, context, count)
+
+ return res
+
+
+
+ def _product_price(self, cr, uid, ids, name, arg, context=None):
+ res = {}
+ if context is None:
+ context = {}
+ quantity = context.get('quantity') or 1.0
+ pricelist = context.get('pricelist', False)
+ if pricelist:
+ for id in ids:
+ try:
+ price = self.pool.get('product.pricelist').price_get(cr,uid,[pricelist], id, quantity, context=context)[pricelist]
+ except:
+ price = 0.0
+ res[id] = price
+ for id in ids:
+ res.setdefault(id, 0.0)
+ return res
+
+ def _product_partner_ref(self, cr, uid, ids, name, arg, context=None):
+ res = {}
+ if context is None:
+ context = {}
+ for p in self.browse(cr, uid, ids, context=context):
+ data = self._get_partner_code_name(cr, uid, [], p, context.get('partner_id', None), context=context)
+ if not data['code']:
+ data['code'] = p.code
+ if not data['name']:
+ data['name'] = p.name
+ res[p.id] = (data['code'] and ('['+data['code']+'] ') or '') + \
+ (data['name'] or '')
+ return res
+
+ _columns = {
+ 'currency_id': fields.many2one('res.currency','Currency'),
+ 'part_number': fields.char('Part Number', size=90),
+ 'default_code' : fields.char('Reference', size=64, select=True),
+ 'import_ok': fields.boolean('Could be imported'),
+ 'cost_fob': fields.float('Cost FOB o Ex Works'),
+ 'fob_currency_id': fields.many2one('res.currency','FoB Currency'),
+ }
+ _sql_constraints = [
+ ('default_code_uniq', 'unique (default_code)', 'El code must be unique!')
+ ]
+ _defaults = {
+ 'import_ok': lambda *a: 1,
+ }
+
+
+ def price_get(self, cr, uid, ids, ptype='list_price', context=None):
+ if context is None:
+ context = {}
+
+ if 'currency_id' in context:
+ pricetype_obj = self.pool.get('product.price.type')
+ price_type_id = pricetype_obj.search(cr, uid, [('field','=',ptype)])[0]
+ price_type_currency_id = pricetype_obj.browse(cr,uid,price_type_id).currency_id.id
+
+ res = {}
+ product_uom_obj = self.pool.get('product.uom')
+ for product in self.browse(cr, uid, ids, context=context):
+ res[product.id] = product[ptype] or 0.0
+ if ptype == 'list_price':
+ res[product.id] = (res[product.id] * (product.price_margin or 1.0)) + \
+ product.price_extra
+ if 'uom' in context:
+ uom = product.uos_id or product.uom_id
+ res[product.id] = product_uom_obj._compute_price(cr, uid,
+ uom.id, res[product.id], context['uom'])
+ if 'currency_id' in context:
+ res[product.id] = self.pool.get('res.currency').compute(cr, uid, price_type_currency_id,
+ context['currency_id'], res[product.id],context=context)
+
+ return res
+
+ def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
+ if not args:
+ args = []
+ if name:
+ ids = self.search(cr, user, [['default_code','ilike',name]]+ args, limit=limit, context=context)
+ if not ids:
+ ids = self.search(cr, user, [['part_number','ilike',name]]+ args, limit=limit, context=context)
+ if not ids:
+ ids = set()
+ ids.update(self.search(cr, user, args + [['default_code',operator,name]], limit=limit, context=context))
+ if len(ids) < limit:
+ ids.update(self.search(cr, user, args + [['name',operator,name]], limit=(limit-len(ids)), context=context))
+ ids = list(ids)
+ if not ids:
+ ptrn = re.compile('(\[(.*?)\])')
+ res = ptrn.search(name)
+ if res:
+ ids = self.search(cr, user, [('default_code','=', res.group(2))] + args, limit=limit, context=context)
+ else:
+ ids = self.search(cr, user, args, limit=limit, context=context)
+ result = self.name_get(cr, user, ids, context=context)
+ return result
+
+product_product()
+
+
=== added file 'product_search_improver/product_view.xml'
--- product_search_improver/product_view.xml 1970-01-01 00:00:00 +0000
+++ product_search_improver/product_view.xml 2013-01-14 15:42:24 +0000
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+ <record id="siesa_product_search_form_view" model="ir.ui.view">
+ <field name="name">product.search.form</field>
+ <field name="model">product.product</field>
+ <field name="type">search</field>
+ <field name="inherit_id" ref="product.product_search_form_view"/>
+ <field name="arch" type="xml">
+ <field name="name" position="replace">
+ <field name="name"/>
+ <field name="part_number"/>
+ <field name="default_code" string="Código"/>
+ </field>
+ </field>
+ </record>
+ <record id="siesa_product_product_tree_view" model="ir.ui.view">
+ <field name="name">product.product.tree</field>
+ <field name="model">product.product</field>
+ <field name="type">tree</field>
+ <field name="inherit_id" ref="product.product_product_tree_view"/>
+ <field eval="7" name="priority"/>
+ <field name="arch" type="xml">
+ <field name="default_code" string="Codigo" position="after">
+ <field name="part_number" />
+ </field>
+ </field>
+ </record>
+
+ <record model="ir.ui.view" id="siesa_view_product_form">
+ <field name="name">product.normal.form</field>
+ <field name="model">product.product</field>
+ <field name="inherit_id" ref="product.product_normal_form_view" />
+ <field name="type">form</field>
+ <field eval="2" name="priority"/>
+ <field name="arch" type="xml">
+ <xpath expr="/form/group/group/field[@name='name']" position="after">
+ <field name="part_number" />
+ </xpath>
+ <xpath expr="/form/group/group/field[@name='purchase_ok']" position="after">
+ <field name="import_ok"/>
+ </xpath>
+ <xpath expr="/form/notebook/page[@string='Information']/group/field[@name='standard_price']" position="replace">
+ <field groups="base.group_sale_manager" name="standard_price" attrs="{'readonly':[('cost_method','=','average')]}" sequence="3"/>
+ </xpath>
+ <xpath expr="/form/notebook/page[@string='Information']/group/field[@name='uom_po_id']" position="after">
+ <separator string="Import Product" colspan="2" attrs="{'invisible':[('import_ok','!=','1')]}"/>
+ <field name="fob_currency_id" string="Import Currency" attrs="{'invisible':[('import_ok','!=','1')]}"/>
+ <field name="cost_fob" string="Import Cost" attrs="{'invisible':[('import_ok','!=','1')]}"/>
+ </xpath>
+ </field>
+ </record>
+ </data>
+</openerp>