deisy 5 лет назад
Сommit
4ad09c049f

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding : utf-8 -*-
+
+from . import models

+ 15 - 0
__openerp__.py

@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+
+{
+    'name': 'Check Crédito/Contado',
+    'version': '8.0.0.1',
+    'category': 'Invoice',
+    'summary': 'Añade campos booleanos de Crédito y Contado en sale_order, purchase_order y account_invoice',
+    'author': 'Eiru Software',
+    'data': [
+        'views/account_invoice_view.xml',
+        'views/sale_order.xml',
+        'views/purchase_order.xml'],
+    'depends': ['base','sale','purchase','sale_stock','account','stock'],
+    'installable':True,
+}

+ 4 - 0
models/__init__.py

@@ -0,0 +1,4 @@
+# -*- coding : utf-8 -*-
+import account_invoice
+import sale_order
+import purchase_order

+ 24 - 0
models/account_invoice.py

@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+from openerp import models, fields, api
+
+class account_invoice(models.Model):
+    _inherit = 'account.invoice'
+
+    contado = fields.Boolean('Contado')
+    credito = fields.Boolean('Crédito')
+
+    _defaults = {
+        'contado': True
+    }
+
+    @api.one
+    @api.onchange('contado')
+    def cambiar_estado_contado(self):
+        self.credito = not self.contado
+        if self.contado == True:
+            self.payment_term = False
+
+    @api.one
+    @api.onchange('credito')
+    def cambiar_estado_credito(self):
+        self.contado = not self.credito

+ 55 - 0
models/purchase_order.py

@@ -0,0 +1,55 @@
+# -*- encoding: utf-8 -*-
+from openerp import models, fields, api, _
+from openerp.exceptions import Warning
+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 purchase_order(models.Model):
+    _inherit = 'purchase.order'
+
+    contado = fields.Boolean('Contado')
+    credito = fields.Boolean('Crédito')
+
+    _defaults = {
+        'contado': True
+    }
+
+
+    @api.one
+    @api.onchange('contado')
+    def cambiar_estado_contado(self):
+        self.credito = not self.contado
+        if self.contado == True:
+            self.payment_term = False
+
+    @api.one
+    @api.onchange('credito')
+    def cambiar_estado_credito(self):
+        self.contado = not self.credito
+
+    def _convert_str_to_datetime(self, date):
+        return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT)
+
+    @api.model
+    def action_invoice_create(self):
+        for purchase in self:
+            inv_id = super(purchase_order, self).action_invoice_create()
+            if inv_id:
+                inv = self.env['account.invoice'].browse(inv_id)
+                date = self._convert_str_to_datetime(purchase.date_order)
+                date = date.strftime(DATE_FORMAT)
+                inv.write({
+                    'date_invoice':date,
+                    'contado':self.contado,
+                    'credito':self.credito
+                })
+                self.update_state()
+
+    @api.multi
+    def update_state(self):
+        for order in self:
+            order.write({'state': 'done'})
+        return True

+ 59 - 0
models/sale_order.py

@@ -0,0 +1,59 @@
+# -*- encoding: utf-8 -*-
+from openerp import models, fields, api, _
+from openerp.exceptions import Warning
+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 sale_order(models.Model):
+    _inherit = 'sale.order'
+
+    contado = fields.Boolean('Contado')
+    credito = fields.Boolean('Crédito')
+
+    _defaults = {
+        'contado': True,
+        'order_policy':'prepaid'
+    }
+
+    @api.one
+    @api.onchange('contado')
+    def cambiar_estado_contado(self):
+        self.credito = not self.contado
+        if self.contado == True:
+            self.payment_term = False
+            self.order_policy = 'prepaid'
+
+    @api.one
+    @api.onchange('credito')
+    def cambiar_estado_credito(self):
+        self.contado = not self.credito
+        if self.credito == True:
+            self.order_policy = 'manual'
+
+
+    def _convert_str_to_datetime(self, date):
+        return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT)
+
+    @api.multi
+    def create_invoice(self):
+        for sale in self:
+            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,
+                    'contado':self.contado,
+                    'credito':self.credito
+                })
+                self.update_state()
+
+    @api.multi
+    def update_state(self):
+        for order in self:
+            order.write({'state': 'done'})
+        return True

BIN
static/description/icon.png


+ 49 - 0
views/account_invoice_view.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="account_invoice_customer_credit" model="ir.ui.view">
+            <field name="name">account.invoice.credit</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_form" />
+            <field name="arch" type="xml">
+              <field name="payment_term" position="replace"/>
+              <field name="account_id" position="after">
+                <label for="contado" string="Forma de pago"/>
+                <div>
+                  <label for="contado" string="Contado"/>
+                  <field name="contado" attrs="{'readonly': [('state','!=','draft')]}"/>
+
+                  <label for="credito" string="Crédito"/>
+                  <field name="credito" attrs="{'readonly' : ['|',('state','!=','draft')]}"/>
+
+                  <field name="payment_term" options="{'no_create': True}" attrs="{'invisible' : [('credito', '=', False )]}"/>
+
+                </div>
+              </field>
+            </field>
+        </record>
+
+        <record id="account_invoice_supplier_credit" model="ir.ui.view">
+                    <field name="name">account.invoice.supplier.credit</field>
+                    <field name="model">account.invoice</field>
+                    <field name="inherit_id" ref="account.invoice_supplier_form" />
+                    <field name="arch" type="xml">
+                      <field name="payment_term" position="replace"/>
+                      <field name="journal_id" position="after">
+                        <label for="contado" string="Forma de pago"/>
+                        <div>
+                          <label for="contado" string="Contado"/>
+                          <field name="contado" attrs="{'readonly': [('state','!=','draft')]}"/>
+
+                          <label for="credito" string="Crédito"/>
+                          <field name="credito" attrs="{'readonly' : ['|',('state','!=','draft')]}"/>
+
+                          <field name="payment_term" options="{'no_create': True}" attrs="{'invisible' : [('credito', '=', False )]}"/>
+
+                        </div>
+                      </field>
+
+                    </field>
+                </record>
+    </data>
+</openerp>

+ 28 - 0
views/purchase_order.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <record id="purchase_order_form_invoice_credit" model="ir.ui.view">
+      <field name="name">purchase_order_form_invoice_credit</field>
+      <field name="model">purchase.order</field>
+      <field name="inherit_id" ref="purchase.purchase_order_form"/>
+      <field name="arch" type="xml">
+
+        <field name="payment_term_id" position="replace"/>
+        <field name="picking_type_id" position="after">
+          <label for="contado" string="Forma de pago"/>
+          <div>
+            <label for="contado" string="Contado"/>
+            <field name="contado" attrs="{'readonly': [('state','!=','draft')]}"/>
+
+            <label for="credito" string="Crédito"/>
+            <field name="credito" attrs="{'readonly' : ['|',('state','!=','draft')]}"/>
+            <field name="payment_term_id" options="{'no_create': True}" attrs="{'invisible' : [('credito', '=', False )],'readonly': [('state','!=','draft')]}"/>
+
+          </div>
+        </field>
+
+        </field>
+    </record>
+
+    </data>
+</openerp>

+ 43 - 0
views/sale_order.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <record id="sale_order_form_invoice_credit" model="ir.ui.view">
+      <field name="name">sale_order_form_invoice_credit</field>
+      <field name="model">sale.order</field>
+      <field name="inherit_id" ref="sale.view_order_form"/>
+      <field name="arch" type="xml">
+
+        <button name="%(sale.action_view_sale_advance_payment_inv)d" states="manual" position="replace">
+          <button name="create_invoice" string="Crear Factura" type="object" states="manual" groups="base.group_user"/>
+        </button>
+
+        <field name="payment_term" position="replace"/>
+        <field name="pricelist_id" position="after">
+          <label for="contado" string="Forma de pago"/>
+          <div>
+            <label for="contado" string="Contado"/>
+            <field name="contado" attrs="{'readonly': [('state','!=','draft')]}"/>
+
+            <label for="credito" string="Crédito"/>
+            <field name="credito" attrs="{'readonly' : ['|',('state','!=','draft')]}"/>
+            <field name="payment_term" options="{'no_create': True}" attrs="{'invisible' : [('credito', '=', False )],'readonly': [('state','!=','draft')]}"/>
+
+          </div>
+        </field>
+
+        </field>
+    </record>
+
+    <record id="view_order_form_inherit" model="ir.ui.view">
+        <field name="name">view_order_form_inherit</field>
+        <field name="model">sale.order</field>
+        <field name="inherit_id" ref="sale_stock.view_order_form_inherit"/>
+        <field name="arch" type="xml">
+          <field name="order_policy" position="replace">
+            <field name="order_policy"/>
+          </field>
+        </field>
+      </record>
+
+    </data>
+</openerp>