Browse Source

Colocar secuencia en la líneas de ventas.

sebas 3 years ago
commit
2d7c46fc04
6 changed files with 198 additions and 0 deletions
  1. 26 0
      __init__.py
  2. 46 0
      __openerp__.py
  3. 26 0
      model/__init__.py
  4. 77 0
      model/sale.py
  5. BIN
      static/description/icon.png
  6. 23 0
      view/sale_view.xml

+ 26 - 0
__init__.py

@@ -0,0 +1,26 @@
+# coding: utf-8
+###############################################################################
+#    Module Writen to OpenERP, Open Source Management Solution
+#    Copyright (C) OpenERP Venezuela (<http://www.vauxoo.com>).
+#    All Rights Reserved
+###############################################################################
+#    Credits:
+#    Coded by: Katherine Zaoral <kathy@vauxoo.com>
+#    Planified by: Nhomar Hernandez <nhomar@vauxoo.com>
+#    Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
+###############################################################################
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as published
+#    by the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+###############################################################################
+
+from . import model

+ 46 - 0
__openerp__.py

@@ -0,0 +1,46 @@
+# coding: utf-8
+###############################################################################
+#    Module Writen to OpenERP, Open Source Management Solution
+#    Copyright (C) OpenERP Venezuela (<http://www.vauxoo.com>).
+#    All Rights Reserved
+###############################################################################
+#    Credits:
+#    Coded by: Katherine Zaoral <kathy@vauxoo.com>
+#    Planified by: Nhomar Hernandez <nhomar@vauxoo.com>
+#    Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
+###############################################################################
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as published
+#    by the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+###############################################################################
+
+{
+    "name": "Sale Order Line Sequence",
+    "summary": "Enumerate sale order lines",
+    "version": "8.0.0.1.6",
+    "author": "Sebastian Penayo/Eiru Software",
+    "website": "http://www.eiru.com/",
+    "license": "AGPL-3",
+    "category": "sale",
+    "depends": [
+        "sale",
+    ],
+    "data": [
+        "view/sale_view.xml",
+    ],
+    "demo": [],
+    "test": [],
+    "qweb": [],
+    "js": [],
+    "css": [],
+    "installable": True,
+}

+ 26 - 0
model/__init__.py

@@ -0,0 +1,26 @@
+# coding: utf-8
+###############################################################################
+#    Module Writen to OpenERP, Open Source Management Solution
+#    Copyright (C) OpenERP Venezuela (<http://www.vauxoo.com>).
+#    All Rights Reserved
+###############################################################################
+#    Credits:
+#    Coded by: Katherine Zaoral <kathy@vauxoo.com>
+#    Planified by: Nhomar Hernandez <nhomar@vauxoo.com>
+#    Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
+###############################################################################
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as published
+#    by the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+###############################################################################
+
+from . import sale

+ 77 - 0
model/sale.py

@@ -0,0 +1,77 @@
+# -*- coding: utf-8 -*-
+# Copyright 2017 Eficent Business and IT Consulting Services S.L.
+# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
+
+from openerp import api, fields, models
+
+
+class SaleOrder(models.Model):
+    _inherit = 'sale.order'
+
+    @api.depends('order_line')
+    def _compute_max_line_sequence(self):
+        """Allow to know the highest sequence entered in sale order lines.
+        Then we add 1 to this value for the next sequence.
+        This value is given to the context of the o2m field in the view.
+        So when we create new sale order lines, the sequence is automatically
+        added as :  max_sequence + 1
+        """
+        self.max_line_sequence = (
+            max(self.mapped('order_line.sequence') or [0]) + 1)
+
+    max_line_sequence = fields.Integer(string='Max sequence in lines',
+                                       compute='_compute_max_line_sequence')
+
+    @api.multi
+    def _reset_sequence(self):
+        for rec in self:
+            current_sequence = 1
+            for line in rec.order_line:
+                line.write({'sequence': current_sequence})
+                current_sequence += 1
+
+    @api.multi
+    def write(self, line_values):
+        res = super(SaleOrder, self).write(line_values)
+        for rec in self:
+            rec._reset_sequence()
+        return res
+
+    @api.multi
+    def copy(self, default=None):
+        if not default:
+            default = {}
+        self2 = self.with_context(keep_line_sequence=True)
+        return super(SaleOrder, self2).copy(default)
+
+
+class SaleOrderLine(models.Model):
+    _inherit = 'sale.order.line'
+
+    # re-defines the field to change the default
+    sequence = fields.Integer(help="Gives the sequence of this line when "
+                                   "displaying the sale order.",
+                              default=9999)
+
+    # displays sequence on the order line
+    sequence2 = fields.Integer(help="Shows the sequence of this line in "
+                               "the sale order.",
+                               related='sequence', readonly=True,
+                               store=True)
+
+    @api.model
+    def create(self, values):
+        line = super(SaleOrderLine, self).create(values)
+        # We do not reset the sequence if we are copying a complete sale order
+        if 'keep_line_sequence' not in self.env.context:
+            line.order_id._reset_sequence()
+        return line
+
+    @api.multi
+    def copy(self, default=None):
+        if not default:
+            default = {}
+        if 'keep_line_sequence' not in self.env.context:
+            default['sequence'] = 9999
+        return super(SaleOrderLine, self).copy(default)

BIN
static/description/icon.png


+ 23 - 0
view/sale_view.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <record id="view_order_form" model="ir.ui.view">
+            <field name="name">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="//field[@name='order_line']" position="before">
+                    <field name="max_line_sequence" invisible="1"/>
+                </xpath>
+                <xpath expr="//field[@name='order_line']" position="attributes">
+                    <attribute name="context">{'default_sequence': max_line_sequence}</attribute>
+                </xpath>
+                <xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="before">
+                    <field name="sequence2" string="Secuencia"/>
+                </xpath>
+            </field>
+        </record>
+
+    </data>
+</openerp>