Jelajahi Sumber

commit inicial

Rodney Elpidio Enciso Arias 5 tahun lalu
melakukan
23ddf590f8
8 mengubah file dengan 275 tambahan dan 0 penghapusan
  1. 1 0
      __init__.py
  2. TEMPAT SAMPAH
      __init__.pyc
  3. 37 0
      __openerp__.py
  4. 1 0
      models/__init__.py
  5. TEMPAT SAMPAH
      models/__init__.pyc
  6. 128 0
      models/sale_order.py
  7. TEMPAT SAMPAH
      models/sale_order.pyc
  8. 108 0
      views/sale_order_view.xml

+ 1 - 0
__init__.py

@@ -0,0 +1 @@
+import models

TEMPAT SAMPAH
__init__.pyc


+ 37 - 0
__openerp__.py

@@ -0,0 +1,37 @@
+# -*- encoding: utf-8 -*-
+
+{
+    'name': 'Sale Order - Lider Constructora',
+    'version': '1.2',
+    'category': 'Sale',
+    'summary': 'Configuracion de ventas para Lider Constructora',
+    'description': """
+
+* Permite establecer si la venta es a credito o contado.
+* Permite registrar el numero de factura fisica en ventas.
+* Automatiza el proceso de venta transferencia, factura.
+* Cambia el estado de la venta al estado hecho.
+* La fecha de la venta se registra en la factura.
+	""",
+    'author': 'OERP - Rodney Enciso Arias',
+    'website': 'www.oerp.eu',
+    'depends': [
+        'sale',
+        'account',
+        'sale_stock',
+        'purchase_order_lider_constructora',
+    ],
+    'data': [
+        'views/sale_order_view.xml',
+    ],
+    'demo': [
+    ],
+    'test': [
+
+    ],
+    'installable': True,
+    'application': False,
+    'auto_install': False,
+    'images': [],
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

+ 1 - 0
models/__init__.py

@@ -0,0 +1 @@
+import sale_order

TEMPAT SAMPAH
models/__init__.pyc


+ 128 - 0
models/sale_order.py

@@ -0,0 +1,128 @@
+# -*- 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 SaleOrder(models.Model):
+    _inherit = 'sale.order'
+    _name = 'sale.order'
+
+    invoice_number = fields.Char('Numero de Factura')
+    contado = fields.Boolean('Contado')
+    credito = fields.Boolean('Crédito')
+
+    _defaults = {
+        'contado': True
+    }
+
+    @api.one
+    @api.onchange('credito')
+    def cambiar_estado_credito(self):
+        self.contado = not self.credito
+
+    @api.one
+    @api.onchange('contado')
+    def cambiar_estado_contado(self):
+        self.credito = not self.contado
+
+    ''' Timezone '''
+    def get_timezone(self):
+        return timezone(self._context.get('tz') or self.env.user.tz)
+
+    def _convert_str_to_datetime(self, date):
+        return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT)
+
+    @api.multi
+    def order_process_now(self):
+        """
+        Confirms order and creates and validates invoice, confirms pickings.
+        """
+        for sale in self:
+            sale.action_button_confirm()
+            inv_id = sale.action_invoice_create()
+            if inv_id:
+                inv = self.env['account.invoice'].browse(inv_id)
+                date = self._convert_str_to_datetime(sale.date_order)
+                date = date.strftime(DATE_FORMAT)
+                inv.write({
+                    'date_invoice':date,
+                    'supplier_invoice_number':self.invoice_number,
+                    'contado':self.contado,
+                    'credito':self.credito
+                })
+                self.update_state()
+                inv.signal_workflow('invoice_open')
+            for picking in sale.picking_ids:
+                picking.force_assign()
+                picking.action_done()
+
+    @api.multi
+    def update_state(self):
+        for order in self:
+            order.write({'state': 'done'})
+        return True
+
+class account_invoice(models.Model):
+    _inherit = 'account.invoice'
+    _name = 'account.invoice'
+
+    contado = fields.Boolean('Contado')
+    credito = fields.Boolean('Crédito')
+
+    _defaults = {
+        'contado': True
+    }
+
+    @api.one
+    @api.onchange('credito')
+    def cambiar_estado_credito(self):
+        self.contado = not self.credito
+
+    @api.one
+    @api.onchange('contado')
+    def cambiar_estado_contado(self):
+        self.credito = not self.contado
+
+class SaleOrderLine(models.Model):
+    _inherit = 'sale.order.line'
+    _name = 'sale.order.line'
+
+    amount_total = fields.Float(compute='_calculate_total_sale_line',string='Total',default=0.0)
+    standard_price = fields.Float(compute='_standard_price',string='Precio de costo',default=0.0)
+
+    discount_id = fields.Many2one(
+        'sale.purchase.discount',
+        string='Desc. Costo',
+        ondelete='restrict'
+    )
+
+    sale_percentage_id = fields.Many2one(
+        'sale.purchase.discount',
+        string='% Venta',
+        ondelete='restrict'
+    )
+
+    @api.depends('price_unit','product_uom_qty')
+    def _calculate_total_sale_line(self):
+        for line in self:
+            line.amount_total = line.product_uom_qty * line.price_unit
+
+    @api.depends('product_id')
+    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)
+            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)
+            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)

TEMPAT SAMPAH
models/sale_order.pyc


+ 108 - 0
views/sale_order_view.xml

@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="view_order_confirm_form" model="ir.ui.view">
+            <field name="name">sale.order.form - Confirm</field>
+            <field name="model">sale.order</field>
+            <field name="inherit_id" ref="sale.view_order_form"/>
+            <field name="arch" type="xml">
+
+                <xpath expr="//tree[@string='Sales Order Lines']//field[@name='name']" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </xpath>
+
+                <xpath expr="//tree[@string='Sales Order Lines']//field[@name='discount']" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </xpath>
+
+                <xpath expr="//tree[@string='Sales Order Lines']//field[@name='price_unit']" position="before">
+                    <field name="standard_price" readonly="1"/>
+                </xpath>
+
+                <xpath expr="//tree[@string='Sales Order Lines']//field[@name='price_unit']" position="before">
+                    <field name="discount_id" domain="[('type','=','purchase')]"/>
+                </xpath>
+
+                <xpath expr="//tree[@string='Sales Order Lines']//field[@name='price_unit']" position="before">
+                    <field name="sale_percentage_id" domain="[('type','=','sale')]"/>
+                </xpath>
+
+                <xpath expr="//tree[@string='Sales Order Lines']//field[@name='price_subtotal']" position="after">
+                    <field name="amount_total" readonly="1"/>
+                </xpath>
+
+                <field name="pricelist_id" position="after">
+                    <field name="contado"/>
+                    <field name="credito"/>
+                    <field name="invoice_number"/>
+                </field>
+
+                <!--
+                    BUTTONS
+                -->
+                <button name="action_button_confirm" states="sent" position="after">
+                    <button name="order_process_now" string="Procesar Venta" type="object" states="draft,sent" groups="base.group_user"/>
+                </button>
+                <button name="action_quotation_send" position="replace">
+                    <button name="action_quotation_send" string="Send by Email" type="object" states="draft" class="oe_highlight" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="action_quotation_send" states="sent,progress,manual" position="replace">
+                    <button name="action_quotation_send" string="Send by Email" type="object" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="print_quotation" states="draft" position="replace">
+                    <button name="print_quotation" string="Print" type="object" states="draft" class="oe_highlight" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="print_quotation" states="sent,progress,manual" position="replace">
+                     <button name="print_quotation" string="Print" type="object" states="sent,progress,manual" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="action_button_confirm" position="replace">
+                   <button name="action_button_confirm" states="draft" string="Confirm Sale" type="object" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="action_button_confirm" position="replace">
+                    <button name="action_button_confirm" states="sent" string="Confirm Sale" class="oe_highlight" type="object" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="invoice_cancel" position="replace">
+                    <button name="invoice_cancel" states="invoice_except" string="Cancel Order" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="cancel" position="replace">
+                    <button name="cancel" states="draft,sent" string="Cancel Quotation" groups="base.group_user" invisible="1"/>
+                </button>
+                <button name="action_cancel" position="replace">
+                    <button name="action_cancel" states="manual,progress" string="Cancel Order" type="object" groups="base.group_user" invisible="1"/>
+                </button>
+
+
+
+            </field>
+        </record>
+
+        <record id="account_invoice_cred_cont" model="ir.ui.view">
+            <field name="name">account.invoice.cred.cont</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_form" />
+            <field name="arch" type="xml">
+                <field name="fiscal_position" position="after">
+                    <field name="contado"/>
+                    <field name="credito"/>
+                </field>
+            </field>
+        </record>
+
+        <record id="order_process_now_action" model="ir.actions.server">
+            <field name="name">Fast Confirm</field>
+            <field name="model_id" ref="model_sale_order"/>
+            <field name="state">code</field>
+            <field name="code">
+                if context.get('active_model') == 'sale.order' and context.get('active_ids'):
+                    self.order_process_now(cr, uid, context['active_ids'], context=context)
+            </field>
+        </record>
+
+        <record id="ir_order_process_now" model="ir.values">
+            <field eval="'client_action_multi'" name="key2"/>
+            <field eval="'sale.order'" name="model"/>
+            <field name="name">Fast Confirm</field>
+            <field eval="'ir.actions.server,%d'%order_process_now_action" name="value"/>
+        </record>
+    </data>
+</openerp>