[FIX] stock_location: fix issue to post message after created pulled procurement
[odoo/odoo.git] / addons / stock_location / stock_location.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import fields,osv
23
24 class stock_location_path(osv.osv):
25     _name = "stock.location.path"
26     _description = "Pushed Flows"
27     _columns = {
28         'name': fields.char('Operation', size=64),
29         'company_id': fields.many2one('res.company', 'Company'),
30         'product_id' : fields.many2one('product.product', 'Products', ondelete='cascade', select=1),
31         'journal_id': fields.many2one('stock.journal','Journal'),
32         'location_from_id' : fields.many2one('stock.location', 'Source Location', ondelete='cascade', select=1, required=True),
33         'location_dest_id' : fields.many2one('stock.location', 'Destination Location', ondelete='cascade', select=1, required=True),
34         'delay': fields.integer('Delay (days)', help="Number of days to do this transition"),
35         'invoice_state': fields.selection([
36             ("invoiced", "Invoiced"),
37             ("2binvoiced", "To Be Invoiced"),
38             ("none", "Not Applicable")], "Invoice Status",
39             required=True,),
40         'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
41         'auto': fields.selection(
42             [('auto','Automatic Move'), ('manual','Manual Operation'),('transparent','Automatic No Step Added')],
43             'Automatic Move',
44             required=True, select=1,
45             help="This is used to define paths the product has to follow within the location tree.\n" \
46                 "The 'Automatic Move' value will create a stock move after the current one that will be "\
47                 "validated automatically. With 'Manual Operation', the stock move has to be validated "\
48                 "by a worker. With 'Automatic No Step Added', the location is replaced in the original move."
49             ),
50     }
51     _defaults = {
52         'auto': 'auto',
53         'delay': 1,
54         'invoice_state': 'none',
55         'picking_type': 'internal',
56     }
57 stock_location_path()
58
59 class product_pulled_flow(osv.osv):
60     _name = 'product.pulled.flow'
61     _description = "Pulled Flows"
62     _columns = {
63         'name': fields.char('Name', size=64, required=True, help="This field will fill the packing Origin and the name of its moves"),
64         'cancel_cascade': fields.boolean('Cancel Cascade', help="Allow you to cancel moves related to the product pull flow"),
65         'location_id': fields.many2one('stock.location','Destination Location', required=True, help="Is the destination location that needs supplying"),
66         'location_src_id': fields.many2one('stock.location','Source Location', help="Location used by Destination Location to supply"),
67         'journal_id': fields.many2one('stock.journal','Journal'),
68         'procure_method': fields.selection([('make_to_stock','Make to Stock'),('make_to_order','Make to Order')], 'Procure Method', required=True, help="'Make to Stock': When needed, take from the stock or wait until re-supplying. 'Make to Order': When needed, purchase or produce for the procurement request."),
69         'type_proc': fields.selection([('produce','Produce'),('buy','Buy'),('move','Move')], 'Type of Procurement', required=True),
70         'company_id': fields.many2one('res.company', 'Company', help="Is used to know to which company the pickings and moves belong."),
71         'partner_address_id': fields.many2one('res.partner', 'Partner Address'),
72         'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
73         'product_id':fields.many2one('product.product','Product'),
74         'invoice_state': fields.selection([
75             ("invoiced", "Invoiced"),
76             ("2binvoiced", "To Be Invoiced"),
77             ("none", "Not Applicable")], "Invoice Status",
78             required=True,),
79     }
80     _defaults = {
81         'cancel_cascade': False,
82         'procure_method': 'make_to_stock',
83         'type_proc': 'move',
84         'picking_type': 'out',
85         'invoice_state': 'none',
86         'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.pulled.flow', context=c),
87     }
88 product_pulled_flow()
89
90 class product_product(osv.osv):
91     _inherit = 'product.product'
92     _columns = {
93         'flow_pull_ids': fields.one2many('product.pulled.flow', 'product_id', 'Pulled Flows'),
94         'path_ids': fields.one2many('stock.location.path', 'product_id',
95             'Pushed Flow',
96             help="These rules set the right path of the product in the "\
97             "whole location tree.")
98     }
99 product_product()
100
101 class stock_move(osv.osv):
102     _inherit = 'stock.move'
103     _columns = {
104         'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too')
105     }
106     def action_cancel(self, cr, uid, ids, context=None):
107         for m in self.browse(cr, uid, ids, context=context):
108             if m.cancel_cascade and m.move_dest_id:
109                 self.action_cancel(cr, uid, [m.move_dest_id.id], context=context)
110         res = super(stock_move,self).action_cancel(cr,uid,ids,context)
111         return res
112 stock_move()
113
114 class stock_location(osv.osv):
115     _inherit = 'stock.location'
116     def chained_location_get(self, cr, uid, location, partner=None, product=None, context=None):
117         if product:
118             for path in product.path_ids:
119                 if path.location_from_id.id == location.id:
120                     return path.location_dest_id, path.auto, path.delay, path.journal_id and path.journal_id.id or False, path.company_id and path.company_id.id or False, path.picking_type
121         return super(stock_location, self).chained_location_get(cr, uid, location, partner, product, context)
122 stock_location()
123 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: