Review: Approve Buenas, Oihane,
Está muy bien la migración del módulo crm_extended. Me ha gustado que quitaras la vista hardcodeada y que la pusieras por herencia con los cambios significativos. Sólo te he hecho tres comentarios in-line de lo mismo. Añade por favor al sistema la tarea de migrar datos para este módulo. Es mejor que cada módulo tenga su propio MP y discusión. Por eso, te pido que para el segundo módulo, crees un nuevo MP. Un saludo. Diff comments: > === modified file 'crm_extended/__init__.py' > --- crm_extended/__init__.py 2014-06-11 10:23:47 +0000 > +++ crm_extended/__init__.py 2014-06-12 16:23:53 +0000 > @@ -1,25 +1,22 @@ > -# -*- coding: utf-8 -*- > +# -*- encoding: utf-8 -*- > > ############################################################################## > # > # OpenERP, Open Source Management Solution > -# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). > +# Copyright (C) 2008-2014 AvanzOSC S.L. (Oihane) All Rights Reserved > # > # 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. > +# 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. > +# GNU 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/>. > +# along with this program. If not, see http://www.gnu.org/licenses/. > # > > ############################################################################## > > -import crm_extended > - > -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: > - > +from . import models > > === modified file 'crm_extended/__openerp__.py' > --- crm_extended/__openerp__.py 2014-06-11 10:23:47 +0000 > +++ crm_extended/__openerp__.py 2014-06-12 16:23:53 +0000 > @@ -3,6 +3,7 @@ > # > # OpenERP, Open Source Management Solution > # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). > +# 2008-2014 AvanzOSC S.L. (Oihane) All Rights Reserved > # > # This program is free software: you can redistribute it and/or modify > # it under the terms of the GNU Affero General Public License as > @@ -26,17 +27,18 @@ > 'category': 'Generic Modules/CRM & SRM', > 'description': """ > This module redesign Incoming calls menu to fit custom needs.""", > - 'depends': ['crm_claim', 'stock', 'base_contact'], > - 'init_xml': [], > - 'update_xml': [ > + 'depends': [ > + 'crm', > + 'crm_claim', > + 'stock', > + ], > + 'data': [ > 'security/ir.model.access.csv', > - 'crm_extended_view.xml', > - ], > - 'demo_xml': [ > - ], > - 'test':[ > + 'views/crm_phonecall_view.xml', > + ], > + 'demo': [ > + ], > + 'test': [ > ], > 'installable': True, > } > - > -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: > > === added directory 'crm_extended/models' > === added file 'crm_extended/models/__init__.py' > --- crm_extended/models/__init__.py 1970-01-01 00:00:00 +0000 > +++ crm_extended/models/__init__.py 2014-06-12 16:23:53 +0000 > @@ -0,0 +1,22 @@ > +# -*- encoding: utf-8 -*- > +############################################################################## > +# > +# OpenERP, Open Source Management Solution > +# Copyright (C) 2008-2014 AvanzOSC S.L. (Oihane) All Rights Reserved > +# > +# 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 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 . import crm_phonecall > \ No newline at end of file > > === renamed file 'crm_extended/crm_extended.py' => > 'crm_extended/models/crm_phonecall.py' > --- crm_extended/crm_extended.py 2014-06-11 10:23:47 +0000 > +++ crm_extended/models/crm_phonecall.py 2014-06-12 16:23:53 +0000 > @@ -3,6 +3,7 @@ > # > # OpenERP, Open Source Management Solution > # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). > +# 2008-2014 AvanzOSC S.L. (Oihane) All Rights Reserved > # > # This program is free software: you can redistribute it and/or modify > # it under the terms of the GNU Affero General Public License as > @@ -19,94 +20,92 @@ > # > > ############################################################################## > > -from osv import osv, fields > -from tools.translate import _ > +from openerp.osv import orm, fields > +from openerp.tools.translate import _ > from datetime import datetime > > > -class crm_phonecall_result(osv.osv): > +class CrmPhonecallResult(orm.Model): > _name = "crm.phonecall.result" > _description = "Phonecall Result" > _columns = { > - 'name': fields.char('Result Name', size=64, required=True, > translate=True), > + 'name': fields.char('Result Name', size=64, > + required=True, translate=True), > } > > -crm_phonecall_result() > > -class crm_phonecall_type(osv.osv): > +class CrmPhonecallType(orm.Model): > _name = "crm.phonecall.type" > _description = "Phonecall Type" > _columns = { > - 'name': fields.char('Type', size=64, required=True, translate=True), > + 'name': fields.char('Type', size=64, > + required=True, translate=True), > } > > -crm_phonecall_type() > > -class crm_phonecall_action(osv.osv): > +class CrmPhonecallAction(orm.Model): > _name = "crm.phonecall.action" > _description = "Phonecall Next Action" > _columns = { > - 'name': fields.char('Next Action', size=64, required=True, > translate=True), > + 'name': fields.char('Next Action', size=64, > + required=True, translate=True), > } > > -crm_phonecall_action() > > -class crm_phonecall(osv.osv): > +class CrmPhonecall(orm.Model): > _inherit = 'crm.phonecall' > _columns = { > 'claim_id': fields.many2one('crm.claim', 'Claim'), > - 'prodlot_id': fields.many2one('stock.production.lot', 'Production > Lot', select=True), > - 'partner_address_id': fields.many2one('res.partner.address', > 'Partner Address', \ > - domain="[('partner_id','=',partner_id)]"), > - 'partner_contact': fields.many2one('res.partner.contact', > 'Contact'), > + 'prodlot_id': fields.many2one('stock.production.lot', > + 'Production Lot', select=True), > 'type_id': fields.many2one('crm.phonecall.type', 'Type of Call'), > 'result_id': fields.many2one('crm.phonecall.result', 'Result of > Call'), > 'action_id': fields.many2one('crm.phonecall.action', 'Next Action'), > } > - > + > def create_claim(self, cr, uid, ids, context=None): > - claim_obj = self.pool.get('crm.claim') > - data_obj = self.pool.get('ir.model.data') > + claim_obj = self.pool['crm.claim'] > + data_obj = self.pool['ir.model.data'] > for phone in self.browse(cr, uid, ids, context=context): > claim_id = claim_obj.create(cr, uid, { > - 'name': phone.name, > - 'date': datetime.now(), > - 'user_id': phone.user_id.id, > - 'section_id': phone.section_id.id, > - 'partner_id': phone.partner_id.id, > - 'partner_address_id': > phone.partner_address_id.id, > - 'email_from': phone.partner_address_id.email, > - 'partner_phone': > phone.partner_address_id.phone, > - 'partner_mobile': > phone.partner_address_id.mobile, > - 'ref': phone.prodlot_id and > ('stock.production.lot,' + str(phone.prodlot_id.id)) or '' > - }, context=context) > - self.write(cr, uid, [phone.id], {'claim_id': claim_id}, > context=context) > - data_id = data_obj._get_id(cr, uid, 'crm_claim', > 'crm_case_claims_form_view') > + 'name': phone.name, > + 'date': datetime.now(), > + 'user_id': phone.user_id.id, > + 'section_id': phone.section_id.id, > + 'partner_id': phone.partner_id.id, > + 'email_from': phone.partner_id.email, > + 'partner_phone': phone.partner_id.phone or > phone.partner_phone, > + 'ref': phone.prodlot_id and ('stock.production.lot,' + > + str(phone.prodlot_id.id)) or '' > + }, context=context) > + self.write(cr, uid, [phone.id], > + {'claim_id': claim_id}, context=context) > + data_id = data_obj._get_id(cr, uid, > + 'crm_claim', > + 'crm_case_claims_form_view') > view_id1 = False > if data_id: > - view_id1 = data_obj.browse(cr, uid, data_id, > context=context).res_id > + view_id1 = data_obj.browse(cr, > + uid, > + data_id, > + context=context).res_id > value = { > - 'name': _('Claim'), > - 'view_type': 'form', > - 'view_mode': 'form,tree', > - 'res_model': 'crm.claim', > - 'view_id': False, > - 'context': context, > - 'views': [(view_id1, 'form')], > - 'type': 'ir.actions.act_window', > - 'nodestroy': True, > - 'res_id': int(claim_id), > - } > + 'name': _('Claim'), > + 'view_type': 'form', > + 'view_mode': 'form,tree', > + 'res_model': 'crm.claim', > + 'view_id': False, > + 'context': context, > + 'views': [(view_id1, 'form')], > + 'type': 'ir.actions.act_window', > + 'nodestroy': True, > + 'res_id': int(claim_id), > + } > return value > > def create(self, cr, uid, vals, context=None): > if not vals.get('duration', None) and vals.get('date', None): > - delta = datetime.now() - datetime.strptime(vals.get('date'), > '%Y-%m-%d %H:%M:%S') > + delta = datetime.now() - datetime.strptime(vals.get('date'), > + '%Y-%m-%d %H:%M:%S') > vals['duration'] = delta.total_seconds()/60 > - return super(crm_phonecall, self).create(cr, uid, vals, > context=context) > - > -crm_phonecall() > - > - > -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: > - > + return super(CrmPhonecall, self).create(cr, uid, vals, > context=context) > > === added directory 'crm_extended/views' > === renamed file 'crm_extended/crm_extended_view.xml' => > 'crm_extended/views/crm_phonecall_view.xml' > --- crm_extended/crm_extended_view.xml 2014-06-11 10:23:47 +0000 > +++ crm_extended/views/crm_phonecall_view.xml 2014-06-12 16:23:53 +0000 > @@ -1,78 +1,30 @@ > <?xml version="1.0"?> > <openerp> > <data> > - > - <record model="ir.ui.view" id="crm.crm_case_inbound_phone_form_view"> > - <field name="arch" type="xml"> > - <form string="Phone Call"> > - <group colspan="4" col="7"> > - <field name="name" required="1"/> > - <field name="duration" widget="float_time"/> > - <label string=" " colspan="2"/> > - <button string="Schedule a Meeting" > - name="action_make_meeting" > - icon="gtk-redo" > - type="object" /> > - <field name="date" required="1"/> > - <field name="user_id"/> > - <field name="section_id" colspan="1" widget="selection" > /> > - <button string="Convert to Opportunity" > - name="%(crm.phonecall2opportunity_act)d" > - icon="gtk-index" type="action" > - > attrs="{'invisible':[('opportunity_id','!=',False)]}" /> > - <label colspan="6" string=""/> > - <button string="Schedule Other Call" > - icon="terp-call-start" > - name="%(crm.phonecall_to_phonecall_act)d" > - type="action" /> > - <field name="type_id"/> > - <field name="result_id"/> > - <field name="claim_id"/> > - <button string="Create Claim" icon="gtk-convert" > - name="create_claim" type="object" > - attrs="{'invisible':[('claim_id','!=',False)]}" > /> > - <field name="action_id"/> > - <field name="prodlot_id"/> > - </group> > - <group col="3" colspan="2"> > - <separator colspan="3" string="Contacts" /> > - <field name="partner_id" > - on_change="onchange_partner_id(partner_id, > email_from)" /> > - <button string="Create a Partner" > - icon="terp-partner" > - name="%(crm.action_crm_phonecall2partner)d" > - type="action" > - attrs="{'invisible':[('partner_id','!=',False)]}" > - groups="base.group_partner_manager" /> > - <newline/> > - <field name="partner_address_id" > - > on_change="onchange_partner_address_id(partner_address_id, email_from)" /> > - <newline/> > - <field name="partner_contact"/> > - <newline/> > - <field name="partner_mobile" /> > - <newline/> > - <field name="partner_phone" /> > - </group> > - <group col="2" colspan="2"> > - <separator colspan="2" string="Categorization" /> > - <field name="categ_id" widget="selection" > - domain="[('object_id.model', '=', 'crm.phonecall')]" > - string="Type" /> > - <field name="priority"/> > - <field name="opportunity_id"/> > - </group> > - <separator string="Description" colspan="4" /> > - <field name="description" nolabel="1" colspan="4" /> > - <separator colspan="4" /> > - </form> > - </field> > - </record> > + <record model="ir.ui.view" id="crm_case_phone_form_view"> > + <field name="name">crm.phonecall.form</field> > + <field name="model">crm.phonecall</field> > + <field name="inherit_id" ref="crm.crm_case_phone_form_view"/> > + <field name="arch" type="xml"> > + <xpath expr="//button[@name='action_make_meeting']" > position="after"> > + <button class="oe_inline oe_stat_button" > + name="create_claim" > + type="object" > + icon="fa-plus-square fa-fw" > + attrs="{'invisible':[('claim_id','!=',False)]}"> > + <div>Create<br/>Claim</div> > + </button> > + </xpath> > + <field name="opportunity_id" position="after"> > + <field name="claim_id"/> > + <field name="prodlot_id"/> > + </field> > + </field> > + </record> > > <record id="view_crm_phonecall_claim_tree" model="ir.ui.view"> > <field name="name">Claim from Phonecall</field> > <field name="model">crm.phonecall</field> > - <field name="type">form</field> > <field name="inherit_id" > ref="crm.crm_case_inbound_phone_tree_view" /> > <field name="arch" type="xml"> > <xpath expr="//button[@string='Convert to Opportunity']" > position="after"> > @@ -81,33 +33,15 @@ > attrs="{'invisible':[('claim_id','!=',False)]}"/> > </xpath> > <field name="partner_phone" position="before"> > - <field name="partner_contact"/> > <field name="prodlot_id"/> > <field name="claim_id" invisible="1"/> > </field> > </field> > </record> > - > - <record id="view_crm_phonecall_claim_search" model="ir.ui.view"> > - <field name="name">Phonecall Search Inherited</field> > - <field name="model">crm.phonecall</field> > - <field name="type">form</field> > - <field name="inherit_id" > ref="crm.view_crm_case_phonecalls_filter" /> > - <field name="arch" type="xml"> > - <xpath expr="//filter[@string='Partner']" position="after"> > - <filter string="Contact" icon="terp-partner" domain="[]" > - context="{'group_by':'partner_address_id'}" /> > - </xpath> > - <field name="partner_id" position="after"> > - <field name="partner_address_id" /> > - </field> > - </field> > - </record> > > <record id="crm_phonecall_result-view" model="ir.ui.view"> > <field name="name">crm.phonecall.result.form</field> > <field name="model">crm.phonecall.result</field> > - <field name="type">form</field> > <field name="arch" type="xml"> > <form string="Phonecall Result"> > <separator string=" " colspan="4"/> > @@ -119,7 +53,6 @@ > <record id="crm_phonecall_result_tree-view" model="ir.ui.view"> > <field name="name">crm.phonecall.result.tree</field> > <field name="model">crm.phonecall.result</field> > - <field name="type">tree</field> > <field name="arch" type="xml"> > <tree string="Phonecall Result"> > <field name="name"/> > @@ -136,13 +69,12 @@ > > <menuitem action="crm_phonecall_result_act" > id="menu_crm_phonecall_result_act" sequence="10" > - groups="base.group_extended" > + groups="base.group_no_one" Mejor no poner directamente el grupo. > parent="crm.menu_crm_config_phonecall" /> > > <record id="crm_phonecall_action-view" model="ir.ui.view"> > <field name="name">crm.phonecall.action.form</field> > <field name="model">crm.phonecall.action</field> > - <field name="type">form</field> > <field name="arch" type="xml"> > <form string="Phonecall Action"> > <separator string=" " colspan="4"/> > @@ -154,7 +86,6 @@ > <record id="crm_phonecall_action_tree-view" model="ir.ui.view"> > <field name="name">crm.phonecall.action.tree</field> > <field name="model">crm.phonecall.action</field> > - <field name="type">tree</field> > <field name="arch" type="xml"> > <tree string="Phonecall Action"> > <field name="name"/> > @@ -171,7 +102,7 @@ > > <menuitem action="crm_phonecall_action_act" > id="menu_crm_phonecall_action_act" sequence="11" > - groups="base.group_extended" > + groups="base.group_no_one" Idem > parent="crm.menu_crm_config_phonecall" /> > > <record id="crm_phonecall_type-view" model="ir.ui.view"> > @@ -206,7 +137,7 @@ > > <menuitem action="crm_phonecall_type_act" > id="menu_crm_phonecall_type_act" sequence="15" > - groups="base.group_extended" > + groups="base.group_no_one" Idem > parent="crm.menu_crm_config_phonecall" /> > > </data> > > === modified file 'dos_fix_min_stock_rules/__init__.py' > --- dos_fix_min_stock_rules/__init__.py 2014-06-11 10:23:47 +0000 > +++ dos_fix_min_stock_rules/__init__.py 2014-06-12 16:23:53 +0000 > @@ -19,6 +19,4 @@ > # > > ############################################################################## > > -import wizard > - > -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: > +from . import wizard > > === modified file 'dos_fix_min_stock_rules/__openerp__.py' > --- dos_fix_min_stock_rules/__openerp__.py 2014-06-11 10:23:47 +0000 > +++ dos_fix_min_stock_rules/__openerp__.py 2014-06-12 16:23:53 +0000 > @@ -21,19 +21,24 @@ > > > { > - "name" : "DOS Fix Min Stock Rules", > - "version" : "1.0", > - "author" : "DOS", > - "category" : "Production,Sale,Stock", > - "website" : "www.dos-sl.es", > - "description": "This module allows you to set minimum stock rules for > the manufacture of packs in function of the sales of a period.", > - "depends" : ["sale", "stock", "product", "procurement"], > - "init_xml" : [], > - "update_xml" : [ > - 'wizard/fix_min_stock_rules_view.xml', > - ], > + "name": "DOS Fix Min Stock Rules", > + "version": "1.0", > + "author": "DOS", > + "category": "Production,Sale,Stock", > + "website": "www.dos-sl.es", > + "description": """ > + This module allows you to set minimum stock rules for the manufacture > + of packs in function of the sales of a period. > + """, > + "depends": [ > + "sale", > + "stock", > + "product", > + "procurement" > + ], > + "data": [ > + 'wizard/fix_min_stock_rules_view.xml', > + ], > "active": False, > "installable": True > } > - > - > > === modified file 'dos_fix_min_stock_rules/wizard/__init__.py' > --- dos_fix_min_stock_rules/wizard/__init__.py 2014-06-11 10:23:47 > +0000 > +++ dos_fix_min_stock_rules/wizard/__init__.py 2014-06-12 16:23:53 > +0000 > @@ -19,8 +19,4 @@ > # > > ############################################################################## > > -import fix_min_stock_rules > - > -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: > - > - > +from . import fix_min_stock_rules > > === modified file 'dos_fix_min_stock_rules/wizard/fix_min_stock_rules.py' > --- dos_fix_min_stock_rules/wizard/fix_min_stock_rules.py 2014-06-11 > 10:23:47 +0000 > +++ dos_fix_min_stock_rules/wizard/fix_min_stock_rules.py 2014-06-12 > 16:23:53 +0000 > @@ -20,135 +20,147 @@ > > ############################################################################## > > import time > -from osv import osv, fields > +from openerp.osv import orm, fields > from datetime import datetime > from dateutil.relativedelta import relativedelta > -from tools.translate import _ > - > -class fix_min_stock_rules_wizard(osv.osv_memory): > - > - _name = 'fix.min.stock.rules.wizard' > - _description = 'Fix Min Stock Rules' > - > - def _get_date_start(self, cr, uid, context=None): > - if context is None: > - context = {} > - date_ref = datetime.now().strftime('%Y-%m-%d') > - first_date = (datetime.strptime(date_ref, '%Y-%m-%d') - > relativedelta(month=2)) > - return first_date.strftime('%Y-%m-%d') > - > - _columns = { > - 'date_start': fields.date('Date start', required=True), > - 'date_end': fields.date('Date end', required=True), > - 'adjust_min_qty': fields.integer('Adjust Min Quantity', > required=True, help="Adjustment on the Min Quantity. "\ > - "When the virtual stock goes belong the Min Quantity, > OpenERP generates "\ > - "a procurement to bring the virtual stock to the Max Quantity."), > - 'percentege_max_qty': fields.integer('Percentage Max Quantity > (%)', required=True, help="Percentage adjustment on the Max Quantity. "\ > - "When the virtual stock goes belong the Max Quantity, > OpenERP generates "\ > - "a procurement to bring the virtual stock to the Max Quantity."), > - } > - > - """ > - 'product_min_qty': fields.integer('Min Quantity', > required=True, help="When the virtual stock goes belong the Min Quantity, > OpenERP generates "\ > - "a procurement to bring the virtual stock to the Max Quantity."), > - 'adjust_max_qty': fields.integer('Adjust Max Quantity', > required=True, help="Adjustment on the Max Quantity. "\ > - "When the virtual stock goes belong the Max Quantity, > OpenERP generates "\ > - "a procurement to bring the virtual stock to the Max Quantity."), > - """ > - > - _defaults = { > - 'date_start': _get_date_start, > - 'date_end': time.strftime('%Y-%m-%d'), > - } > - > - > - def calculate_product_sales(self, cr, uid, product_id, date_start, > date_end): > - > - total = 0 > - > - sql = "SELECT COALESCE(sum(product_uom_qty), 0) / 2 As > total_sales " > - sql += "FROM sale_order s " > - sql += "INNER JOIN sale_order_line l ON s.id=l.order_id " > - sql += "WHERE s.date_order >= '" + date_start + "' AND > s.date_order <= '" + date_end + "' " > - sql += "AND l.state IN ('confirmed', 'done') " > - sql += "AND l.pack_product_id=" + str(product_id)+ " " > - > - cr.execute(sql) > - > - result = cr.dictfetchall() > - > - for res in result: > - total += res['total_sales'] > - > - return total > - > - > - def calculate_min_stock_rules(self, cr, uid, ids, context=None): > - if context is None: > - context = {} > - > - data = self.browse(cr, uid, ids)[0] > - product_obj = self.pool.get('product.product') > - stock_warehouse_obj = self.pool.get('stock.warehouse') > - stock_warehouse_orderpoint_obj = > self.pool.get('stock.warehouse.orderpoint') > - > - #Comprobamos que hay al menos un almacen definido > - #Obtenemos Ubicacion Stock > - location_id = None > - stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, []) > - > - for warehouse in stock_warehouse_obj.browse(cr, uid, > stock_warehouse_ids, context): > - location_id = warehouse.lot_stock_id and > warehouse.lot_stock_id.id or None > - break > - > - #Validaciones > - if not location_id: > - raise osv.except_osv(_('Location of stock not defined > !'), _('Not set a location of stock in the stock warehouse by default.')) > - > - if data.percentege_max_qty < 0 or data.percentege_max_qty > 100: > - raise osv.except_osv(_('Incorrect percentage !'), > _('The maximum quantity percentage must be between 0 and 100.')) > - > - > - #Obtenemos todos los productos cuyo metodo suministro sea > Producir (Pack) > - product_ids = product_obj.search(cr, uid, [('supply_method', > '=', 'produce')]) > - for product in product_obj.browse(cr, uid, product_ids, > context=context): > - > - total_product_sales = self.calculate_product_sales(cr, > uid, product.id, data.date_start, data.date_end) > - product_min_qty = total_product_sales + > data.adjust_min_qty > - product_max_qty = round(product_min_qty + > (product_min_qty * data.percentege_max_qty / 100), 0) > - > - if product_min_qty > product_max_qty: > - product_max_qty = product_min_qty > - > - stock_warehouse_orderpoint_ids = > stock_warehouse_orderpoint_obj.search(cr, uid, [('product_id', '=', > product.id), ('location_id', '=', location_id)]) > - > - if stock_warehouse_orderpoint_ids: > - #Existe regla stock mínimo > - stock_warehouse_orderpoint_id = > stock_warehouse_orderpoint_ids[0] > - > - #Modificamos regla de stock mínimo con los > nuevos valores > - stock_warehouse_orderpoint_obj.write(cr, uid, > [stock_warehouse_orderpoint_id], { > - 'product_max_qty': product_max_qty, > - 'product_min_qty': product_min_qty, > - }) > - > - else: > - #Si no existe regla de stock mínimo, la creamos > - vals = {} > - > - vals['location_id'] = location_id > - vals['logic'] = 'max' > - vals['product_id'] = product.id > - vals['product_max_qty'] = product_max_qty > - vals['product_min_qty'] = product_min_qty > - vals['product_uom'] = 1 > - vals['qty_multiple'] = 1 > - vals['warehouse_id'] = 1 > - > - stock_warehouse_orderpoint_obj.create(cr, uid, > vals, context=context) > - > - return {'type': 'ir.actions.act_window_close',} > - > -fix_min_stock_rules_wizard() > - > -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: > \ No newline at end of file > +from openerp.tools.translate import _ > + > + > +class FixMinStockRulesWizard(orm.TransientModel): > + > + _name = 'fix.min.stock.rules.wizard' > + _description = 'Fix Min Stock Rules' > + > + def _get_date_start(self, cr, uid, context=None): > + if context is None: > + context = {} > + date_ref = datetime.now().strftime('%Y-%m-%d') > + first_date = (datetime.strptime(date_ref, > + '%Y-%m-%d') - relativedelta(month=2)) > + return first_date.strftime('%Y-%m-%d') > + > + _columns = { > + 'date_start': fields.date('Date start', required=True), > + 'date_end': fields.date('Date end', required=True), > + 'adjust_min_qty': > + fields.integer('Adjust Min Quantity', required=True, > + help="Adjustment on the Min Quantity. When the > virtual " > + "stock goes belong the Min Quantity, penERP generates > " > + "a procurement to bring the virtual stock to the Max " > + "Quantity."), > + 'percentege_max_qty': > + fields.integer('Percentage Max Quantity (%)', required=True, > + help="Percentage adjustment on the Max Quantity. When > " > + "the virtual stock goes belong the Max Quantity, " > + "OpenERP generates a procurement to bring the virtual > " > + "stock to the Max Quantity."), > + } > + > + _defaults = { > + 'date_start': _get_date_start, > + 'date_end': time.strftime('%Y-%m-%d'), > + } > + > + def calculate_product_sales(self, cr, uid, product_id, > + date_start, date_end): > + total = 0 > + > + sql = "SELECT COALESCE(sum(product_uom_qty), 0) / 2 As total_sales " > + sql += "FROM sale_order s " > + sql += "INNER JOIN sale_order_line l ON s.id=l.order_id " > + sql += "WHERE s.date_order >= '" + date_start + "' " > + sql += "AND s.date_order <= '" + date_end + "' " > + sql += "AND l.state IN ('confirmed', 'done') " > + sql += "AND l.pack_product_id=" + str(product_id) + " " > + > + cr.execute(sql) > + > + result = cr.dictfetchall() > + > + for res in result: > + total += res['total_sales'] > + > + return total > + > + def calculate_min_stock_rules(self, cr, uid, ids, context=None): > + if context is None: > + context = {} > + > + data = self.browse(cr, uid, ids)[0] > + product_obj = self.pool['product.product'] > + warehouse_obj = self.pool['stock.warehouse'] > + orderpoint_obj = self.pool['stock.warehouse.orderpoint'] > + > + #Comprobamos que hay al menos un almacen definido > + #Obtenemos Ubicacion Stock > + location_id = None > + warehouse_ids = warehouse_obj.search(cr, uid, []) > + > + for warehouse in warehouse_obj.browse(cr, uid, warehouse_ids, > context): > + location_id = (warehouse.lot_stock_id and > + warehouse.lot_stock_id.id) or None > + break > + > + #Validaciones > + if not location_id: > + raise orm.except_orm(_('Location of stock not defined !'), > + _('Not set a location of stock in the stock > ' > + 'warehouse by default.')) > + > + if data.percentege_max_qty < 0 or data.percentege_max_qty > 100: > + raise orm.except_orm(_('Incorrect percentage !'), > + _('The maximum quantity percentage must be ' > + 'between 0 and 100.')) > + > + #Obtenemos los productos cuyo metodo suministro sea Producir (Pack) > + product_ids = product_obj.search(cr, uid, > + [('supply_method', '=', 'produce')], > + context=context) > + for product in product_obj.browse(cr, uid, product_ids, > + context=context): > + total_product_sales = self.calculate_product_sales(cr, uid, > + product.id, > + > data.date_start, > + data.date_end) > + product_min_qty = total_product_sales + data.adjust_min_qty > + product_max_qty = round(product_min_qty > + + (product_min_qty * > + data.percentege_max_qty / 100), 0) > + > + if product_min_qty > product_max_qty: > + product_max_qty = product_min_qty > + > + orderpoint_ids = orderpoint_obj.search(cr, uid, > + [('product_id', '=', > + product.id), > + ('location_id', '=', > + location_id)]) > + > + if orderpoint_ids: > + #Existe regla stock mínimo > + orderpoint_id = orderpoint_ids[0] > + > + #Modificamos regla de stock mínimo con los nuevos valores > + orderpoint_obj.write(cr, uid, > + [orderpoint_id], > + {'product_max_qty': product_max_qty, > + 'product_min_qty': product_min_qty, > + }) > + > + else: > + #Si no existe regla de stock mínimo, la creamos > + vals = { > + 'localtion_id': location_id, > + 'logic': 'max', > + 'product_id': product.id, > + 'product_max_qty': product_max_qty, > + 'product_min_qty': product_min_qty, > + 'product_uom': 1, > + 'qty_multiple': 1, > + 'warehouse_id': 1, > + } > + > + orderpoint_obj.create(cr, uid, vals, > + context=context) > + > + return {'type': 'ir.actions.act_window_close'} > > === modified file > 'dos_fix_min_stock_rules/wizard/fix_min_stock_rules_view.xml' > --- dos_fix_min_stock_rules/wizard/fix_min_stock_rules_view.xml > 2014-06-11 10:23:47 +0000 > +++ dos_fix_min_stock_rules/wizard/fix_min_stock_rules_view.xml > 2014-06-12 16:23:53 +0000 > @@ -2,41 +2,48 @@ > <openerp> > <data> > > - <record id="fix_min_stock_rules_wizard_view" model="ir.ui.view"> > - <field name="name">Fix Min Stock Rules</field> > - <field name="model">fix.min.stock.rules.wizard</field> > - <field name="type">form</field> > - <field name="arch" type="xml"> > - <form string="Fix Min Stock Rules"> > - <newline/> > - <label colspan="4" width="220" > string="Calculate the minimum stock rules packs (mix model-operators) in > terms of sales over a set period:"/> > - <separator colspan="4"/> > - <group colspan="4" col="4"> > - <field name="date_start"/> > - <field name="date_end"/> > - <field name="adjust_min_qty"/> > - <field > name="percentege_max_qty"/> > - </group> > - <separator colspan="4"/> > - <group colspan="4" col="4"> > - <button special="cancel" > string="Cancel" icon="gtk-cancel"/> > - <button > name="calculate_min_stock_rules" string="Calculate" type="object" > icon="gtk-ok"/> > - </group> > - </form> > - </field> > - </record> > + <record id="fix_min_stock_rules_wizard_view" model="ir.ui.view"> > + <field name="name">Fix Min Stock Rules</field> > + <field name="model">fix.min.stock.rules.wizard</field> > + <field name="arch" type="xml"> > + <form string="Fix Min Stock Rules"> > + <newline/> > + <label colspan="4" width="220" > + string="Calculate the minimum stock rules packs > + (mix model-operators) in terms of sales over a set > + period:"/> > + <separator colspan="4"/> > + <group colspan="4" col="4"> > + <field name="date_start"/> > + <field name="date_end"/> > + <field name="adjust_min_qty"/> > + <field name="percentege_max_qty"/> > + </group> > + <separator colspan="4"/> > + <group colspan="4" col="4"> > + <button special="cancel" string="Cancel" > icon="gtk-cancel"/> > + <button name="calculate_min_stock_rules" > + string="Calculate" type="object" > + icon="gtk-ok"/> > + </group> > + </form> > + </field> > + </record> > > - <record id="action_fix_min_stock_rules_wizard" > model="ir.actions.act_window"> > - <field name="name">Fix Min Stock Rules Wizard</field> > - <field name="type">ir.actions.act_window</field> > - <field > name="res_model">fix.min.stock.rules.wizard</field> > - <field name="view_type">form</field> > - <field name="view_mode">form</field> > - <field name="view_id" > ref="fix_min_stock_rules_wizard_view"/> > - <field name="target">new</field> > - </record> > - > - <menuitem name="Fix Min Stock Rules" > id="menu_fix_min_stock_rules" parent="procurement.menu_stock_sched" > action="action_fix_min_stock_rules_wizard" sequence="40"/> > + <record id="action_fix_min_stock_rules_wizard" > + model="ir.actions.act_window"> > + <field name="name">Fix Min Stock Rules Wizard</field> > + <field name="type">ir.actions.act_window</field> > + <field name="res_model">fix.min.stock.rules.wizard</field> > + <field name="view_type">form</field> > + <field name="view_mode">form</field> > + <field name="view_id" ref="fix_min_stock_rules_wizard_view"/> > + <field name="target">new</field> > + </record> > + > + <menuitem name="Fix Min Stock Rules" id="menu_fix_min_stock_rules" > + parent="stock.menu_stock_sched" > + action="action_fix_min_stock_rules_wizard" sequence="40"/> > > </data> > </openerp> > \ No newline at end of file > -- https://code.launchpad.net/~oihanecruce/avanzosc/migrate2/+merge/222971 Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas. -- Mailing list: https://launchpad.net/~avanzosc Post to : [email protected] Unsubscribe : https://launchpad.net/~avanzosc More help : https://help.launchpad.net/ListHelp

