Ver código fonte

commit inicial

Adrielso 8 anos atrás
commit
17e9c7a484

+ 26 - 0
__init__.py

@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2015 Mohamed M. Hagag.
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
+#                       Jordi Esteve <jesteve@zikzakmedia.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 wizard
+

BIN
__init__.pyc


+ 41 - 0
__openerp__.py

@@ -0,0 +1,41 @@
+# -*- 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/>.
+#
+##############################################################################
+{
+    'name': 'Sale Pricelist Recalculation',
+    'version': '1.0',
+    'category': 'Sales',
+    'sequence': 1,
+    'description': """
+        This module adds a wizard on sales order which will let the user change the pricelist
+        and the concerned sale order lines will take an effect.
+     """,
+    'author': 'OpenERP SA/ Adrielso kunert',
+    'depends': ['sale'],
+    'init_xml': [],
+    'update_xml': [
+        'wizard/wizard_sale_pricelist_recalculation.xml',
+        'wizard/sale_order.xml',
+    ],
+    'demo_xml': [],
+    'installable': True,
+    'active': False,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

+ 26 - 0
wizard/__init__.py

@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
+#                       Jordi Esteve <jesteve@zikzakmedia.com>
+#    $Id$
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU 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 General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import wizard_sale_pricelist_recalculation
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
wizard/__init__.pyc


+ 25 - 0
wizard/sale_order.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+      <record id="button_change_pricelist_products" model="ir.ui.view">
+        <field name="name">button.change.pricelist.products</field>
+        <field name="model">sale.order</field>
+        <field name="inherit_id" ref="sale.view_order_form"/>
+        <field name="arch" type="xml">
+          <field name="pricelist_id" position="replace">
+              <field domain="[('type','=','sale')]" name="pricelist_id" groups="product.group_sale_pricelist" on_change="onchange_pricelist_id(pricelist_id,order_line)" options="{'no_create':True}" readonly="1"/>
+          </field>
+
+          <field name="pricelist_id" position="after">
+              <label for="pricelist_id" string="Actualizar Tarifa"/>
+              <div>
+                  <button name="%(action_change_pricelist)d" type="action" string="Tarifa" icon="gtk-jump-to"
+                        class="oe_button oe_form_button oe_highlight" help="Seleccionar Lista de Precio"
+                         attrs="{'invisible': [('state', 'not in', ['draft', 'sent'])]}"/>
+
+              </div>
+          </field>
+        </field>
+      </record>
+    </data>
+</openerp>

+ 55 - 0
wizard/wizard_sale_pricelist_recalculation.py

@@ -0,0 +1,55 @@
+# -*- 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 openerp.osv import osv, fields
+from openerp.tools import translate
+
+
+class sale_extended_wizard(osv.osv_memory):
+    _name = "sale.extended.wizard"
+    _description = "Sale Extended wizard"
+    _columns = {
+        'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, domain=[('type','=','sale')])
+    }
+
+    def change_pricelist_products(self, cr, uid, ids, context):
+        obj_curr = self.browse(cr, uid, ids, context)[0]
+        order_line_obj = self.pool.get('sale.order.line')
+        sale_order_pool = self.pool.get('sale.order')
+        pricelist_id = obj_curr['pricelist_id']
+        sale_obj = sale_order_pool.browse(cr, uid, context['active_id'], context)
+        partner_id = sale_obj.partner_id.id
+        date_order = sale_obj.date_order
+
+        if sale_obj.pricelist_id.id == pricelist_id.id:
+            raise osv.except_osv(_('Warning'),_('The Pricelist is already applied to the sales order!'))
+
+        if sale_obj['state'] == 'draft':
+            sale_order_pool.write(cr, uid, context['active_id'], {'pricelist_id': pricelist_id.id})
+            for line in sale_obj.order_line:
+                vals = order_line_obj.product_id_change(cr, uid, line.id, pricelist_id.id, line.product_id.id ,qty=line.product_uom_qty,uom=line.product_uom.id,uos=line.product_uos.id, partner_id=partner_id, date_order=date_order)
+                if vals.get('value',False):
+                    if 'price_unit' in vals['value'].keys():
+                        order_line_obj.write(cr, uid, line.id, {'price_unit': vals['value']['price_unit']},context=context)
+        else:
+            raise osv.except_osv(_('Warning'),_('PriceList cannot be changed! Make sure the Sales Order is in "Quotation" state!'))
+        return {}
+
+sale_extended_wizard()

BIN
wizard/wizard_sale_pricelist_recalculation.pyc


+ 46 - 0
wizard/wizard_sale_pricelist_recalculation.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <record model="ir.ui.view" id="view_sale_inherited">
+            <field name="name">view.sale.inherited</field>
+            <field name="model">sale.extended.wizard</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+            <form string="Price Change">
+                <field name="pricelist_id" />
+                <group col="2" colspan="2">
+                    <!-- <button icon="gtk-cancel" special="cancel" string="Close"/> -->
+                    <button name="change_pricelist_products" string="Change" type="object" icon="gtk-ok"/>
+                </group>
+            </form>
+            </field>
+        </record>
+
+<!--        <record id="action_sale_extended" model="ir.actions.act_window">-->
+<!--            <field name="name">Price List</field>-->
+<!--            <field name="type">ir.actions.act_window</field>-->
+<!--            <field name="res_model">sale.extended.wizard</field>-->
+<!--            <field name="view_mode">form</field>-->
+<!--            <field name="view_id" ref="view_sale_inherited"/> -->
+<!--    	</record>-->
+      <record model="ir.actions.act_window" id="action_change_pricelist">
+            <field name="name">Cambiar Precio</field>
+            <field name="res_model">sale.extended.wizard</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="view_id" ref="view_sale_inherited"/>
+            <field name="target">new</field>
+      </record>
+
+    <act_window
+            id="sale_pricelist_act_window"
+            name="Change Pricelist"
+            view_mode="form"
+            view_type="form"
+            res_model="sale.extended.wizard"
+            src_model="sale.order"
+            target="new"
+            key2="client_action_multi"	/>
+    </data>
+</openerp>