Skip to content

Commit

Permalink
Merge d08d944 into 8e9d44d
Browse files Browse the repository at this point in the history
  • Loading branch information
rami-wafaie committed Aug 2, 2016
2 parents 8e9d44d + d08d944 commit bac91c6
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 0 deletions.
50 changes: 50 additions & 0 deletions stock_picking_on_hold/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

===================================================
Sale Payment Method - Hold Pickings (until payment)
===================================================

This module allows to hold the picking until the invoice is paid

Usage
=====

* go to ...
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas

:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/186/8.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
=======

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

* Thomas Rehn <thomas.rehn@initos.com>
* Katja Matthes <katja.matthes@initos.com>

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 stock_picking_on_hold/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# © initOS GmbH 2016
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import account_invoice
from . import payment_method
from . import stock
24 changes: 24 additions & 0 deletions stock_picking_on_hold/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# © initOS GmbH 2016
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{'name': 'Sale Payment Method - Hold Pickings (until payment)',
'version': '8.0.1.0.0',
'category': 'Warehouse',
'description': """
Sale Payment Method - Hold Pickings (until payment)
===================================================
* This module allows to hold the picking until the invoice is paid
""",
'depends': ['stock',
'sale',
'sale_payment_method_automatic_workflow',
],
'author': "initOS GmbH, Odoo Community Association (OCA)",
'license': 'AGPL-3',
'data': ['views/stock.xml',
'views/payment_method.xml',
],
'installable': True,
'application': False,
}
27 changes: 27 additions & 0 deletions stock_picking_on_hold/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# © initOS GmbH 2016
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

@api.multi
def confirm_paid(self):
"""
When an invoice is paid
a picking that is hold until payment may need a status check.
"""
res = super(AccountInvoice, self).confirm_paid()
# collect all pickings to check
pickings_to_check = self.env['stock.picking']
for invoice in self:
for sale in invoice.sale_ids:
for picking in sale.picking_ids:
if picking.state == 'hold':
pickings_to_check += picking
# trigger availability check
pickings_to_check.action_assign()
return res
15 changes: 15 additions & 0 deletions stock_picking_on_hold/payment_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# © initOS GmbH 2016
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields


class PaymentMethod(models.Model):
_inherit = 'payment.method'

hold_picking_until_payment = fields.Boolean(
string='Hold Picking Until Payment',
help="If set to true, pickings will not be automatically confirmed"
"when the invoice has not been paid."
)
117 changes: 117 additions & 0 deletions stock_picking_on_hold/stock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# -*- coding: utf-8 -*-
# © initOS GmbH 2016
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api
from openerp.osv import fields


class StockMove(models.Model):
_inherit = 'stock.move'

@api.multi
def action_assign(self):
for move in self:
if move.picking_id:
# Write dummy variable so that the state of the
# picking will be updated.
move.picking_id.dummy_int_to_trigger_state_update = \
(move.picking_id.dummy_int_to_trigger_state_update + 1) % 2
if self._context.get('payment_check', True) and \
move.picking_id.is_on_hold():
# Do not assign picking because it is on hold
return False
return super(StockMove, self).action_assign()


class StockPicking(models.Model):
_inherit = 'stock.picking'

def _state_get(self, cr, uid, ids, field_name, arg, context=None):
res = super(StockPicking, self).\
_state_get(cr, uid, ids, field_name, arg, context=context)
pickings = self.browse(cr, uid, res.keys(), context=context)
for picking in pickings:
if res[picking.id] == 'confirmed' and picking.is_on_hold():
res[picking.id] = 'hold'
return res

def _get_pickings(self, cr, uid, ids, context=None):
# Method is copied from stock/stock.py.
# Calling _get_pickings of `super(StockPicking, self)` doesn't work
# because when the method is being called, `self` is a stock.move.
res = set()
for move in self.browse(cr, uid, ids, context=context):
if move.picking_id:
res.add(move.picking_id.id)
return list(res)

_columns = {
'state': fields.function(
_state_get,
type="selection",
copy=False,
store={
'stock.picking': (
lambda self, cr, uid, ids, ctx: ids,
['move_type', 'dummy_int_to_trigger_state_update'], 20),
'stock.move': (
_get_pickings,
['state', 'picking_id', 'partially_available'], 20)},
selection=[
('draft', 'Draft'),
('cancel', 'Cancelled'),
('waiting', 'Waiting Another Operation'),
('confirmed', 'Waiting Availability'),
('partially_available', 'Partially Available'),
('hold', 'Waiting For Payment'),
('assigned', 'Ready to Transfer'),
('done', 'Transferred'),
],
string='Status',
readonly=True,
select=True,
track_visibility='onchange',
help="""
* Draft: not confirmed yet and will not be
scheduled until confirmed\n
* Waiting Another Operation: waiting for another move to
proceed before \n
it becomes automatically available
(e.g. in Make-To-Order flows)\n
* Waiting Availability: still waiting for the availability
of products\n
* Waiting For Payment: waiting for the payment
of the related sale order\n
* Partially Available: some products are available and reserved\n
* Ready to Transfer: products reserved,
simply waiting for confirmation.\n
* Transferred: has been processed,
can't be modified or cancelled anymore\n
* Cancelled: has been cancelled, can't be confirmed anymore"""
),
# In an ideal world "On Hold" would be a computed field that depends on
# the payment status of the sale order. Unfortunately the changes
# to the v7-functional fields 'sale_id.invoiced' don't seem to be
# propagated to the new api.depends mechanism. There we use this ugly
# workaround that forces the re-computation of the state whenever
# action_assign is called.
'dummy_int_to_trigger_state_update': fields.integer(
string='Dummy Integer (to trigger update of state field)'
)
}

@api.multi
def is_on_hold(self):
"""Returns True iff picking should be held because the
corresponding order has not been paid yet."""
self.ensure_one()
if self.sale_id and self.sale_id.payment_method_id and\
self.sale_id.payment_method_id.hold_picking_until_payment and\
not self.sale_id.invoiced:
return True
return False

@api.multi
def action_assign_unpaid(self):
self.with_context(payment_check=False).action_assign()
15 changes: 15 additions & 0 deletions stock_picking_on_hold/views/payment_method.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="payment_method_view_form" model="ir.ui.view">
<field name="name">sale_payment_method.payment_method.view_form</field>
<field name="model">payment.method</field>
<field name="inherit_id" ref="sale_payment_method_automatic_workflow.payment_method_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='workflow_process_id']" position="after">
<field name="hold_picking_until_payment"/>
</xpath>
</field>
</record>
</data>
</openerp>
27 changes: 27 additions & 0 deletions stock_picking_on_hold/views/stock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//header/button[@name='action_assign']" position="attributes">
<attribute name="states">confirmed,hold</attribute>
</xpath>
<xpath expr="//header/button[@name='action_assign']" position="after">
<button name="action_assign_unpaid" states="hold" string="Check Availability (No Payment Check)" type="object" groups="base.group_user"/>
</xpath>
<xpath expr="//header/button[@name='force_assign']" position="attributes">
<attribute name="states">confirmed,waiting,partially_available,hold</attribute>
</xpath>
<xpath expr="//header/button[@name='action_cancel']" position="attributes">
<attribute name="states">assigned,confirmed,partially_available,draft,waiting,hold</attribute>
</xpath>
<xpath expr="//header/field[@name='state']" position="attributes">
<attribute name="statusbar_colors">{"shipping_except":"red","invoice_except":"red","waiting_date":"blue","hold":"red"}</attribute>
</xpath>
</field>
</record>
</data>
</openerp>

0 comments on commit bac91c6

Please sign in to comment.