Rodney Elpidio Enciso Arias 5 lat temu
commit
dc19a3c5df
6 zmienionych plików z 210 dodań i 0 usunięć
  1. 1 0
      .gitignore
  2. 1 0
      __init__.py
  3. 35 0
      __openerp__.py
  4. 1 0
      models/__init__.py
  5. 101 0
      models/purchase_order.py
  6. 71 0
      views/purchase_order_view.xml

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 1 - 0
__init__.py

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

+ 35 - 0
__openerp__.py

@@ -0,0 +1,35 @@
+# -*- encoding: utf-8 -*-
+
+{
+    'name': 'Purchase Order - Agroyguazu',
+    'version': '1.2',
+    'category': 'Purchase',
+    'summary': 'Configuracion de compras para Agroyguazu',
+    'description': """
+
+* Permite establecer si la compra es a credito o contado.
+* Permite registrar el numero de factura fisica en compras.
+* Automatiza el proceso de compra transferencia, factura.
+* La fecha de la compra se registra en la factura.
+	""",
+    'author': 'OERP - Rodney Enciso Arias',
+    'website': 'www.oerp.eu',
+    'depends': [
+        'purchase',
+        'account',
+        'purchase_discount',
+    ],
+    'data': [
+        'views/purchase_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 purchase_order

+ 101 - 0
models/purchase_order.py

@@ -0,0 +1,101 @@
+# -*- 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 PurchaseOrder(models.Model):
+    _inherit = 'purchase.order'
+    _name = 'purchase.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 purchase_process_now(self):
+        """
+        Confirms order and creates and validates invoice, confirms pickings.
+        """
+        for purchase in self:
+            self.update_state()
+            inv_id = purchase.action_invoice_create()
+            if inv_id:
+                inv = self.env['account.invoice'].browse(inv_id)
+                # import web_pdb; web_pdb.set_trace()
+                date = self._convert_str_to_datetime(purchase.date_order)
+                date = date.strftime(DATE_FORMAT)
+                inv.write({
+                    'date_invoice':date,
+                    'supplier_invoice_number':self.invoice_number,
+                    'contado':self.contado,
+                    'credito':self.credito,
+                })
+                inv.signal_workflow('invoice_open')
+
+            purchase.action_picking_create()
+            for picking in purchase.picking_ids:
+                picking.force_assign()
+                picking.action_done()
+
+    @api.multi
+    def update_state(self):
+        for order in self:
+            order.write({'state': 'approved'})
+        return True
+
+
+class PurchaseOrderLine(models.Model):
+    _inherit = 'purchase.order.line'
+    _name = 'purchase.order.line'
+
+    amount_total = fields.Float(compute='_calculate_total_purchase_line',string='Total',default=0.0)
+
+    @api.depends('discount','price_unit','product_qty')
+    def _calculate_total_purchase_line(self):
+        for line in self:
+            line.amount_total = line.product_qty * (line.price_unit - ((line.price_unit * (line.discount or 0.0))/100.0))
+
+class AccountInvoice(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

+ 71 - 0
views/purchase_order_view.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <!--
+            PURCHASE ORDER
+        -->
+        <record id="purchase_order_line_total" model="ir.ui.view">
+            <field name="name">purchase.order.line.total</field>
+            <field name="model">purchase.order</field>
+            <field name="inherit_id" ref="purchase.purchase_order_form"/>
+            <field name="arch" type="xml">
+                <!--
+                    PURCHASE ORDER
+                -->
+                <field name="picking_type_id" position="after">
+                    <field name="contado" attrs="{'readonly':[('state','in',('approved','done'))]}"/>
+                    <field name="credito" attrs="{'readonly':[('state','in',('approved','done'))]}"/>
+                    <field name="invoice_number" attrs="{'readonly':[('state','in',('approved','done'))]}"/>
+                </field>
+                <!--
+                    PURCHASE ORDER LINE
+                -->
+                <xpath expr="//tree[@string='Purchase Order Lines']//field[@name='price_subtotal']" position="after">
+                    <field name="amount_total" readonly="1"/>
+                </xpath>
+                <xpath expr="//tree[@string='Purchase Order Lines']//field[@name='date_planned']" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </xpath>
+                <xpath expr="//tree[@string='Purchase Order Lines']//field[@name='name']" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </xpath>
+                <xpath expr="//tree[@string='Purchase Order Lines']//field[@name='product_uom']" position="attributes">
+                    <attribute name="string">Unidad de Medida</attribute>
+                </xpath>
+                <!--
+                    BUTTONS
+                -->
+                <button name="bid_received" states="sent" position="after">
+                    <button name="purchase_process_now" string="Procesar Compra" type="object" states="draft,sent" groups="base.group_user" class="oe_highlight"/>
+                </button>
+                <button name="print_quotation" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </button>
+                <button name="wkf_send_rfq" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </button>
+                <button name="purchase_confirm" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </button>
+                <button name="wkf_send_rfq" states="approved" position="attributes">
+                    <attribute name="invisible">1</attribute>
+                </button>
+            </field>
+        </record>
+
+        <!--
+            ACCOUNT INVOICE
+        -->
+        <record id="account_invoice_supplier_cred_cont" model="ir.ui.view">
+            <field name="name">account.invoice.supplier.cred.cont</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_supplier_form" />
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='journal_id']" position="after">
+                    <field name="contado"/>
+                    <field name="credito"/>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>