Parcourir la source

Para hacer descuento sobre el total de la factura tanto por porcentaje como monto fijo

sebastian il y a 5 ans
commit
3c3bbf7ede

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import wizard
+import purchase

BIN
__init__.pyc


+ 40 - 0
__openerp__.py

@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Purchase Global Discount",
+
+    'summary': """
+    """,
+
+    'description': """
+Purchase Global Discount
+========================
+Option to set fix and percentage discount.
+
+Percentage Discount
+-------------------
+A percentage amount deducted from each line as disount
+
+Fixed Discount
+--------------
+Fixed amount is divided based on subtotal and deducted from each line
+    """,
+
+    'author': "Aasim Ahmed Ansari",
+    'website': "http://aasimania.wordpress.com",
+
+    # Categories can be used to filter modules in modules listing
+    # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
+    # for the full list
+    'category': 'Purchase Management',
+    'version': '0.1',
+
+    # any module necessary for this one to work correctly
+    'depends': ['purchase','product'],
+
+    # always loaded
+    'data': [
+        'security/purchase_security.xml',
+        'wizard/purchase_global_discount_wizard_view.xml',
+        'purchase_view.xml',
+    ],
+}

+ 18 - 0
purchase.py

@@ -0,0 +1,18 @@
+from openerp.osv import fields, osv
+import openerp.addons.decimal_precision as dp
+
+class purchase_order_line(osv.osv):
+    _inherit = 'purchase.order.line'
+
+    def _get_orig_price_unit(self, cr, uid, ids, field_name, arg, context=None):
+        res={}
+        purchase_lines = self.browse(cr, uid, ids, context=context)
+        for line in purchase_lines:
+            if not line.discount:
+                res[line.id] = line.price_unit
+        return res
+
+    _columns = {
+        'orig_price_unit': fields.function(_get_orig_price_unit, string='Orig. Precio Unit.', type='float',digits_compute= dp.get_precision('Product Price'), store=True),
+        'discount': fields.char('Descuento', readonly=True),
+    }

BIN
purchase.pyc


+ 50 - 0
purchase_view.xml

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        
+        <record id="purchase_order_line_form_global_discount_wizard_inherit1" model="ir.ui.view">
+            <field name="name">purchase.order.line.form.global_discount.wizard.inherit1</field>
+            <field name="model">purchase.order.line</field>
+            <field name="inherit_id" ref="purchase.purchase_order_line_form" />
+            <field name="arch" type="xml">
+                <field name="price_unit" position="before">
+                    <field name="orig_price_unit"/>
+                </field>
+                
+                <field name="price_unit" position="after">
+                    <field name="discount"/>
+                </field>
+            </field>
+        </record>
+        
+        <record id="purchase_order_form_purchase_global_discount_wizard_inherit1" model="ir.ui.view">
+            <field name="name">purchase.order.purchase.order.global_discount.wizard.inherit1</field>
+            <field name="model">purchase.order</field>
+            <field name="inherit_id" ref="purchase.purchase_order_form" />
+            <field name="arch" type="xml">
+                <field name="order_line" position="before">
+                    <button name="%(action_purchase_global_discount_wizard_form)d" string="Set Global Discount" 
+                            type="action" attrs="{'invisible':[('state','not in',['draft','sent'])]}" 
+                            groups="purchase.group_purchase_user, purchase.group_purchase_manager" />
+                </field>
+                
+                <xpath expr="//page[@string='Products']/field[@name='order_line']/tree" position="attributes">
+                    <attribute name="editable"/>
+                </xpath>
+                <xpath expr="//page[@string='Products']/field[@name='order_line']/tree/field[@name='price_unit']" position="before">
+                    <field name="orig_price_unit" />
+                </xpath>
+                
+                <xpath expr="//page[@string='Products']/field[@name='order_line']/tree/field[@name='price_unit']" position="after">
+                    <field name="discount" />
+                </xpath>
+                
+                <xpath expr="//page[@string='Products']/field[@name='order_line']/tree/field[@name='company_id']" position="replace">
+                </xpath>
+            </field>
+        </record>
+        
+    </data>
+</openerp>    
+            
+            

+ 2 - 0
security/ir.model.access.csv

@@ -0,0 +1,2 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_purchase_global_fix_discount_purchase_global_fix_discount,purchase_global_fix_discount.purchase_global_fix_discount,model_purchase_global_fix_discount_purchase_global_fix_discount,,1,0,0,0

+ 11 - 0
security/purchase_security.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data noupdate="0">
+    
+    <record id="group_discount_per_po_line" model="res.groups">
+        <field name="name">Discount on purchase lines</field>
+        <field name="category_id" ref="base.module_category_hidden"/>
+    </record>
+
+</data>
+</openerp>

BIN
static/description/icon.png


+ 31 - 0
static/description/index.html

@@ -0,0 +1,31 @@
+<section class="oe_container oe_dark">
+    <div class="oe_row oe_spaced">
+        <div class="oe_span12">
+            <h2 class="oe_slogan">Odoo- Purchase Management</h2>
+            <h3 class="oe_slogan">Purchase Global Discount</h3>
+        </div>
+        <p class="oe_mt32">
+            Option to set fix and percentage discount. <br /><br />
+            <b>Percentage Discount</b><br />
+            A percentage amount deducted from each line<br /><br />
+            <b>Fixed Discount</b><br />
+            Fixed amount is divided based on subtotal and deducted from each line
+        </p>
+    </div>
+</section>
+<br/>
+<section class="oe_container oe_dark">
+    <div class="oe_row "> 
+        <div class="oe_slogan text-center">
+            <div class="oe_span12">
+                <h2 class="text-center"><a>About Me</a></h2>
+            </div>
+            <span>
+                <a style="color: #a24689 !important;" href="https://in.linkedin.com/in/aasimansari" target="new"><img src="linkedin.png" height="25" width="25" /></a> | 
+                <a style="color: #a24689 !important;" href="https://twitter.com/aasimansari" target="new"><img src="twitter.png" height="25" width="25" /></a> | 
+                <a style="color: #a24689 !important;" href="http://aasimania.wordpress.com" target="new"><img src="wordpress.png" height="25" width="25" /></a> | 
+                <a style="color: #a24689 !important;" href="mailto:aasim333@gmail.com"><img src="mailto.png" height="25" width="25" /></a>
+            </span>
+        </div>
+    </div>
+</section>

BIN
static/description/linkedin.png


BIN
static/description/mailto.png


BIN
static/description/twitter.png


BIN
static/description/wordpress.png


+ 1 - 0
wizard/__init__.py

@@ -0,0 +1 @@
+import purchase_global_discount_wizard

BIN
wizard/__init__.pyc


+ 41 - 0
wizard/purchase_global_discount_wizard.py

@@ -0,0 +1,41 @@
+from openerp import models, fields, api
+import logging
+from datetime import datetime
+#from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
+_logger = logging.getLogger(__name__)
+
+
+class purchase_global_discount_wizard(models.TransientModel):
+    _name = "purchase.order.global_discount.wizard"
+
+    # todo implement fixed amount
+    type = fields.Selection([
+         ('percentage', 'Porcentaje'),
+         ('fixed_amount', 'Monto fijo'),
+         ],
+         'Tipo',
+         required=True,
+         default='fixed_amount',
+         )
+    amount = fields.Float(
+        # 'Amount',
+        'Descuento',
+        required=True,
+        )
+
+    @api.multi
+    def confirm(self):
+        self.ensure_one()
+        order = self.env['purchase.order'].browse(
+            self._context.get('active_id', False))
+
+        if self.type == 'percentage':
+            for line in order.order_line:
+                line.discount = str(self.amount) + "%"
+                line.price_unit = line.orig_price_unit * (1 - (self.amount or 0.0) / 100.0)
+        else:
+            total_amount = order.amount_untaxed
+            for line in order.order_line:
+                line.discount = ((line.price_subtotal / total_amount) * self.amount) / line.product_qty
+                line.price_unit = float(line.orig_price_unit) - float(line.discount)
+        return True

BIN
wizard/purchase_global_discount_wizard.pyc


+ 32 - 0
wizard/purchase_global_discount_wizard_view.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <record id="view_purchase_global_discount_wizard_form" model="ir.ui.view">
+            <field name="name">Purchase Order Global Discount Wizard</field>
+            <field name="model">purchase.order.global_discount.wizard</field>
+            <field name="arch" type="xml">
+                <form string="Descuento global">
+                    <!-- <field name="type"/> -->
+                    <group>
+                        <field name="type"/>
+                        <field name="amount"/>
+                    </group>
+                    <footer>
+                        <button name="confirm" string="Confirm" type="object" class="oe_highlight"/>
+                        or
+                        <button string="_Cancel" class="oe_link" special="cancel" />
+                    </footer>
+                </form>
+            </field>
+        </record>
+
+        <record id="action_purchase_global_discount_wizard_form" model="ir.actions.act_window">
+            <field name="name">Global Discount Wizard</field>
+            <field name="res_model">purchase.order.global_discount.wizard</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="target">new</field>
+        </record>
+
+    </data>
+</openerp>