forked from akretion/stock-logistics-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stock.py
61 lines (56 loc) · 2.55 KB
/
stock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (c) 2012 Andrea Cometa All Rights Reserved.
# www.andreacometa.it
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# Ported to new API by Alexis de Lattre <[email protected]>
#
# 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 openerp import models, api, _, workflow, exceptions
class stock_picking(models.Model):
_inherit = 'stock.picking'
@api.multi
def has_valuation_moves(self):
self.ensure_one()
account_moves = self.env['account.move'].search(
[('ref', '=', self.name)])
return bool(account_moves)
@api.multi
def action_revert_done(self):
for picking in self:
if picking.has_valuation_moves():
raise exceptions.Warning(
_('Picking %s has valuation moves: '
'remove them first.')
% (picking.name))
if picking.invoice_id:
raise exceptions.Warning(
_('Picking %s has invoices!') % (picking.name))
picking.move_lines.write({'state': 'draft'})
picking.state = 'draft'
if picking.invoice_state == 'invoiced' and not picking.invoice_id:
picking.invoice_state = '2binvoiced'
# Deleting the existing instance of workflow
workflow.trg_delete(
self._uid, 'stock.picking', picking.id, self._cr)
workflow.trg_create(
self._uid, 'stock.picking', picking.id, self._cr)
picking.message_post(
_("The picking has been re-opened and set to draft state"))
return