[IMP] improved meta data on __openerp__.py
[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 import tools
24 import ir
25 import pooler
26
27 class stock_location_path(osv.osv):
28     _name = "stock.location.path"
29     _description = "Pushed Flows"
30     _columns = {
31         'name': fields.char('Operation', size=64),
32         'company_id': fields.many2one('res.company', 'Company'),
33         'product_id' : fields.many2one('product.product', 'Products', ondelete='cascade', select=1),
34         'journal_id': fields.many2one('stock.journal','Journal'),
35         'location_from_id' : fields.many2one('stock.location', 'Source Location', ondelete='cascade', select=1, required=True),
36         'location_dest_id' : fields.many2one('stock.location', 'Destination Location', ondelete='cascade', select=1, required=True),
37         'delay': fields.integer('Delay (days)', help="Number of days to do this transition"),
38         'invoice_state': fields.selection([
39             ("invoiced", "Invoiced"),
40             ("2binvoiced", "To Be Invoiced"),
41             ("none", "Not from Picking")], "Invoice Status",
42             required=True,),
43         '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"),
44         'auto': fields.selection(
45             [('auto','Automatic Move'), ('manual','Manual Operation'),('transparent','Automatic No Step Added')],
46             'Automatic Move',
47             required=True, select=1,
48             help="This is used to define paths the product has to follow within the location tree.\n" \
49                 "The 'Automatic Move' value will create a stock move after the current one that will be "\
50                 "validated automatically. With 'Manual Operation', the stock move has to be validated "\
51                 "by a worker. With 'Automatic No Step Added', the location is replaced in the original move."
52             ),
53     }
54     _defaults = {
55         'auto': lambda *arg: 'auto',
56         'delay': lambda *arg: 1,
57         'invoice_state': lambda *args: 'none',
58         'picking_type':lambda *args:'out',
59     }
60 stock_location_path()
61
62 class product_pulled_flow(osv.osv):
63     _name = 'product.pulled.flow'
64     _description = "Pulled Flows"
65     _columns = {
66         'name': fields.char('Name', size=64, required=True, help="This field will fill the packing Origin and the name of its moves"),
67         'cancel_cascade': fields.boolean('Cancel Cascade', help="Allow you to cancel moves related to the product pull flow"),
68         'location_id': fields.many2one('stock.location','Location', required=True, help="Is the destination location that needs supplying"),
69         'location_src_id': fields.many2one('stock.location','Location Source', help="Location used by Destination Location to supply"),
70         'journal_id': fields.many2one('stock.journal','Journal'),
71         '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."),
72         'type_proc': fields.selection([('produce','Produce'),('buy','Buy'),('move','Move')], 'Type of Procurement', required=True),
73         'company_id': fields.many2one('res.company', 'Company', help="Is used to know to which company belong packings and moves"),
74         'partner_address_id': fields.many2one('res.partner.address', 'Partner Address'),
75         '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"),
76         'product_id':fields.many2one('product.product','Product'),
77         'invoice_state': fields.selection([
78             ("invoiced", "Invoiced"),
79             ("2binvoiced", "To Be Invoiced"),
80             ("none", "Not from Picking")], "Invoice Status",
81             required=True,),
82     }
83     _defaults = {
84         'cancel_cascade': False,
85         'procure_method': 'make_to_stock',
86         'type_proc': 'move',
87         'picking_type': 'out',
88         'invoice_state': 'none',
89         'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.pulled.flow', context=c),
90     }
91 product_pulled_flow()
92
93 class product_product(osv.osv):
94     _inherit = 'product.product'
95     _columns = {
96         'flow_pull_ids': fields.one2many('product.pulled.flow', 'product_id', 'Pulled Flows'),
97         'path_ids': fields.one2many('stock.location.path', 'product_id',
98             'Pushed Flow',
99             help="These rules set the right path of the product in the "\
100             "whole location tree.")
101     }
102 product_product()
103
104 class stock_move(osv.osv):
105     _inherit = 'stock.move'
106     _columns = {
107         'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too')
108     }
109     def action_cancel(self,cr,uid,ids,context={ }):
110         for m in self.browse(cr, uid, ids, context=context):
111             if m.cancel_cascade and m.move_dest_id:
112                 self.action_cancel(cr, uid, [m.move_dest_id.id], context=context)
113         res = super(stock_move,self).action_cancel(cr,uid,ids,context)
114         return res
115 stock_move()
116
117 class stock_location(osv.osv):
118     _inherit = 'stock.location'
119     def chained_location_get(self, cr, uid, location, partner=None, product=None, context={}):
120         if product:
121             for path in product.path_ids:
122                 if path.location_from_id.id == location.id:
123                     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
124         return super(stock_location, self).chained_location_get(cr, uid, location, partner, product, context)
125 stock_location()
126 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: