Browse Source

[ADD] interes de venta

Rodney Elpidio Enciso Arias 5 years ago
parent
commit
83bf3ae3c8

+ 1 - 0
__openerp__.py

@@ -23,6 +23,7 @@
     ],
     'data': [
         'views/sale_order_view.xml',
+        'views/sale_interest_percentage_view.xml',
     ],
     'demo': [
     ],

+ 1 - 0
models/__init__.py

@@ -1 +1,2 @@
 import sale_order
+import sale_interest_percentage

BIN
models/__init__.pyc


+ 47 - 0
models/sale_interest_percentage.py

@@ -0,0 +1,47 @@
+# -*- encoding: utf-8 -*-
+
+from openerp import models, api, fields
+from pytz import timezone
+from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
+from datetime import datetime,timedelta
+
+DATE_FORMAT = '%Y-%m-%d'
+
+class SaleInterestPercentage(models.Model):
+    _name = 'sale.interest.percentage'
+
+    name = fields.Char('Nombre')
+    value = fields.Float(string='Valor',default=0.0)
+
+class SaleOrder(models.Model):
+    _inherit = 'sale.order'
+    _name = 'sale.order'
+
+    interest_id = fields.Many2one(
+        'sale.interest.percentage',
+        string="Interes de venta"
+    )
+
+    @api.onchange('interest_id')
+    def _calculate_interest(self):
+        for order in self:
+            for line in order.order_line:
+                line.interest_amount = order.interest_id.value
+                if line.discount_id and not line.sale_percentage_id:
+                    price_unit = line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)
+                    line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
+
+                if line.sale_percentage_id and not line.discount_id:
+                    price_unit = line.standard_price + ((line.standard_price * (line.sale_percentage_id.value or 0.0))/100)
+                    line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
+
+                if line.discount_id and line.sale_percentage_id:
+                    price_unit = (line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) + (((line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) * (line.sale_percentage_id.value or 0.0))/100)
+                    line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
+
+
+class SaleOrderLine(models.Model):
+    _inherit = 'sale.order.line'
+    _name = 'sale.order.line'
+
+    interest_amount = fields.Float(string='Interes %',default=0.0)

BIN
models/sale_interest_percentage.pyc


+ 8 - 4
models/sale_order.py

@@ -115,14 +115,18 @@ class SaleOrderLine(models.Model):
     def _standard_price(self):
         for line in self:
             line.standard_price = line.product_id.standard_price
-            # line.price_unit = line.product_id.standard_price
 
     @api.onchange('discount_id','sale_percentage_id')
     def _calculate_price_unit(self):
         for line in self:
             if line.discount_id and not line.sale_percentage_id:
-                line.price_unit = line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)
+                price_unit = line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)
+                line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
+
             if line.sale_percentage_id and not line.discount_id:
-                line.price_unit = line.standard_price + ((line.standard_price * (line.sale_percentage_id.value or 0.0))/100)
+                price_unit = line.standard_price + ((line.standard_price * (line.sale_percentage_id.value or 0.0))/100)
+                line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
+
             if line.discount_id and line.sale_percentage_id:
-                line.price_unit = (line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) + (((line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) * (line.sale_percentage_id.value or 0.0))/100)
+                price_unit = (line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) + (((line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) * (line.sale_percentage_id.value or 0.0))/100)
+                line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)

BIN
models/sale_order.pyc


+ 104 - 0
views/sale_interest_percentage_view.xml

@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="sale_interest_percentage_search_form_view" model="ir.ui.view">
+           <field name="name">sale.interest.percentage.search.form</field>
+           <field name="model">sale.interest.percentage</field>
+           <field name="arch" type="xml">
+                <search string="Sale Interest percentage">
+                    <field name="name"/>
+                </search>
+           </field>
+        </record>
+
+        <record id="sale_interest_percentage_form_view" model="ir.ui.view">
+            <field name="name">sale.interest.percentage.form</field>
+            <field name="model">sale.interest.percentage</field>
+            <field name="arch" type="xml">
+                <form string="Sale Interest Percentage" version="7.0">
+                    <sheet>
+                        <div class="oe_title">
+                            <div class="oe_edit_only">
+                                <label for="name" string="Nombre del Interes"/>
+                            </div>
+                            <h1>
+                                <field name="name"/>
+                            </h1>
+                        </div>
+                        <group>
+                            <field name="value"/>
+                        </group>
+                    </sheet>
+                </form>
+            </field>
+        </record>
+
+        <record id="sale_interest_percentage_tree_view" model="ir.ui.view">
+            <field name="name">sale.interest.percentage.tree</field>
+            <field name="model">sale.interest.percentage</field>
+            <field name="arch" type="xml">
+                <tree string="Sale Interest Percentage">
+                    <field name="name"/>
+                    <field name="value"/>
+                </tree>
+            </field>
+        </record>
+
+
+
+        <record id="discount_sale_view_form" model="ir.ui.view">
+            <field name="name">discount.sale.order.form</field>
+            <field name="model">sale.order</field>
+            <field name="inherit_id" ref="sale.view_order_form"/>
+            <field name="arch" type="xml">
+                <!-- <xpath expr="//tree/field[@name='discount']" position="attributes">
+                    <attribute name="digits">(16, 2)</attribute>
+                </xpath> -->
+
+                <!-- <xpath expr="//tree[@string='Sales Order Lines']//field[@name='product_uom']" position="after">
+                    <attribute name="invisible">1</attribute>
+                </xpath> -->
+
+                <xpath expr="//group[@name='sale_total']" position="replace">
+                    <group col="4">
+                        <group name="discount" colspan="2">
+                            <field name="interest_id"/>
+                        </group>
+                        <group class="oe_subtotal_footer oe_right" colspan="2" name="sale_total">
+                            <field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                           <!-- <field name="amount_discount" widget='monetary' options="{'currency_field': 'currency_id'}"/> -->
+                            <field name="amount_tax" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                            <div class="oe_subtotal_footer_separator oe_inline">
+                                <label for="amount_total" />
+                                <button name="button_dummy"
+                                       states="draft,sent" string="(update)" type="object" class="oe_edit_only oe_link"/>
+                            </div>
+                            <field name="amount_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                       </group>
+                    </group>
+                </xpath>
+
+           </field>
+        </record>
+
+
+        <record model="ir.actions.act_window" id="action_sale_interest_percentage">
+            <field name="name">Configurar Interes de Ventas</field>
+            <field name="res_model">sale.interest.percentage</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,form</field>
+        </record>
+
+        <menuitem
+            name="Configurar Interes de Venta"
+            id="menu_sale_interest_percentage_parent"
+            parent="base.menu_base_config"/>
+
+        <menuitem
+            name="Porcentajes de interes en ventas"
+            id="menu_sale_interest_percentage"
+            action="action_sale_interest_percentage"
+            parent="menu_sale_interest_percentage_parent"/>
+
+    </data>
+</openerp>

+ 4 - 0
views/sale_order_view.xml

@@ -27,6 +27,10 @@
                     <field name="sale_percentage_id" domain="[('type','=','sale')]"/>
                 </xpath>
 
+                <xpath expr="//tree[@string='Sales Order Lines']//field[@name='price_unit']" position="before">
+                    <field name="interest_amount" readonly="1"/>
+                </xpath>
+
                 <xpath expr="//tree[@string='Sales Order Lines']//field[@name='price_subtotal']" position="after">
                     <field name="amount_total" readonly="1"/>
                 </xpath>