Skip to content

Commit

Permalink
[ADD] sale_order_line_sequence v10
Browse files Browse the repository at this point in the history
  • Loading branch information
serpentcs-dev1 committed Jul 6, 2017
1 parent 6555201 commit 60523f6
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ addons:
- python-simplejson
- python-serial
- python-yaml
- wkhtmltopdf

env:
global:
- VERSION="10.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- VERSION="10.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0" WKHTMLTOPDF_VERSION="0.12.4"
- TRANSIFEX_USER='[email protected]'
- secure: mTXYvzW7/+xP465dNW0p9H+Q8jVgQXmqm8zo+ntZC6ESkTudj6xUkrjJcfzp9LGomxoG6N+6TezjFuhfGKCAc4S2manxj9YQoHvZMHJvt73VsMZU2QLfE+IMAdFS/AeBpYLNE8VvdKIGhiFwvHyRqaF0vAGwmcsOdS2NQb/hoiY=

Expand Down
57 changes: 57 additions & 0 deletions sale_order_line_sequence/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=============================
Sale Order Line with Sequence
=============================

Displays the sequence of Sale order line and helps to maintain the order.


Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/167/10.0


Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback


Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.


Contributors
------------

* Eficent Business and IT Consulting Services S.L. <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.

7 changes: 7 additions & 0 deletions sale_order_line_sequence/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- 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 . import model
from .init_hooks import post_init_hook
23 changes: 23 additions & 0 deletions sale_order_line_sequence/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- 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).

{
"name": "Sale Order Line Sequence",
"summary": "Propagates SO line sequence to invoices and stock picking.",
"version": "10.0.1.0.0",
"author": "Eficent, "
"Serpent CS, "
"Odoo Community Association (OCA)",
"category": "Sales",
"website": "https://www.eficent.com/",
"license": "AGPL-3",
'data': ['views/sale_view.xml',
'views/report_saleorder.xml'],
"depends": [
"sale",
],
'post_init_hook': 'post_init_hook',
"installable": True,
}
16 changes: 16 additions & 0 deletions sale_order_line_sequence/init_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- 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 odoo import SUPERUSER_ID
from odoo.api import Environment


def post_init_hook(cr, pool):
"""
Fetches all the sale order and resets the sequence of the order lines
"""
env = Environment(cr, SUPERUSER_ID, {})
sale = env['sale.order'].search([])
sale._reset_sequence()
6 changes: 6 additions & 0 deletions sale_order_line_sequence/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- 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 . import sale_order
69 changes: 69 additions & 0 deletions sale_order_line_sequence/model/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- 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 odoo import api, fields, models


class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.multi
@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
"""
for sale in self:
sale.max_line_sequence = (
max(sale.mapped('order_line.sequence') or [0]) + 1)

max_line_sequence = fields.Integer(string='Max sequence in lines',
compute='_compute_max_line_sequence',
store=True)

@api.multi
def _reset_sequence(self):
for rec in self:
current_sequence = 1
for line in rec.order_line:
line.sequence = current_sequence
current_sequence += 1

@api.multi
def write(self, line_values):
res = super(SaleOrder, self).write(line_values)
self._reset_sequence()
return res

@api.multi
def copy(self, default=None):
return super(SaleOrder,
self.with_context(keep_line_sequence=True)).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 self.env.context.get('keep_line_sequence'):
line.order_id._reset_sequence()
return line
13 changes: 13 additions & 0 deletions sale_order_line_sequence/views/report_saleorder.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_saleorder_document_sequence" inherit_id="sale.report_saleorder_document">
<xpath expr="//table[@class='table table-condensed']/thead/tr/th[1]" position="before">
<th><strong>Sequence</strong></th>
</xpath>
<xpath expr="//table[@class='table table-condensed']/tbody[@class='sale_tbody']/t[1]/t[2]/tr[1]/td[1]" position="before">
<td>
<span t-field="l.sequence2"/>
</td>
</xpath>
</template>
</odoo>
21 changes: 21 additions & 0 deletions sale_order_line_sequence/views/sale_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<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"/>
</xpath>
</field>
</record>

</odoo>

0 comments on commit 60523f6

Please sign in to comment.