~unifield-team/unifield-wm/us-826

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2012 TeMPO Consulting, MSF. All Rights Reserved
#
#    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 osv import osv
from osv import fields
from os import path
from tools.translate import _

from spreadsheet_xml.spreadsheet_xml_write import SpreadsheetCreator
from msf_doc_import.wizard import AUTO_SUPPLY_COLUMNS_HEADER_FOR_IMPORT as columns_header_for_auto_supply
from msf_doc_import.wizard import AUTO_SUPPLY_LINE_COLUMNS_FOR_IMPORT as columns_for_auto_supply
from msf_doc_import.wizard import ORDER_CYCLE_COLUMNS_HEADER_FOR_IMPORT as columns_header_for_order_cycle
from msf_doc_import.wizard import ORDER_CYCLE_LINE_COLUMNS_FOR_IMPORT as columns_for_order_cycle
from msf_doc_import.wizard import THRESHOLD_COLUMNS_HEADER_FOR_IMPORT as columns_header_for_threshold
from msf_doc_import.wizard import THRESHOLD_LINE_COLUMNS_FOR_IMPORT as columns_for_threshold
from msf_doc_import import GENERIC_MESSAGE

import base64

class automatic_supply_rule(osv.osv):
    """
    We override the class for import of Automatic supply rule lines
    """
    _inherit = 'stock.warehouse.automatic.supply'

    def wizard_import_auto_supply_line(self, cr, uid, ids, context=None):
        '''
        Launches the wizard to import lines from a file
        '''
        # Objects
        wiz_obj = self.pool.get('wizard.import.auto.supply.line')

        context = context is None and {} or context

        if isinstance(ids, (int, long)):
            ids = [ids]

        context.update({'active_id': ids[0]})

        rule = self.browse(cr, uid, ids[0], context=context)
        header_cols = columns_header_for_auto_supply
        cols = columns_for_auto_supply

        columns_header = [(_(f[0]), f[1]) for f in header_cols]
        default_template = SpreadsheetCreator(_('Template of import'), columns_header, [])
        file = base64.encodestring(default_template.get_xml(default_filters=['decode.utf8']))
        export_id = wiz_obj.create(cr, uid, {'file': file,
                                             'filename_template': 'Auto Supply template.xls',
                                             'filename': 'Lines_Not_Imported.xls',
                                             'message': """%s %s""" % (GENERIC_MESSAGE, ', '.join([_(f) for f in cols])),
                                             'rule_id': ids[0],
                                             'state': 'draft',}, context=context)

        return {'type': 'ir.actions.act_window',
                'res_model': 'wizard.import.auto.supply.line',
                'res_id': export_id,
                'view_type': 'form',
                'view_mode': 'form',
                'target': 'crush',
                'context': context,
                }

automatic_supply_rule()

class order_cycle_rule(osv.osv):
    """
    We override the class for import of Order cycle rule lines
    """
    _inherit = 'stock.warehouse.order.cycle'

    def wizard_import_order_cycle_line(self, cr, uid, ids, context=None):
        '''
        Launches the wizard to import lines from a file
        '''
        # Objects
        wiz_obj = self.pool.get('wizard.import.order.cycle.line')

        context = context is None and {} or context

        if isinstance(ids, (int, long)):
            ids = [ids]

        context.update({'active_id': ids[0]})

        rule = self.browse(cr, uid, ids[0], context=context)
        header_cols = columns_header_for_order_cycle
        cols = columns_for_order_cycle

        columns_header = [(_(f[0]), f[1]) for f in header_cols]
        default_template = SpreadsheetCreator(_('Template of import'), columns_header, [])
        file = base64.encodestring(default_template.get_xml(default_filters=['decode.utf8']))
        export_id = wiz_obj.create(cr, uid, {'file': file,
                                             'filename_template': 'Order Cycle template.xls',
                                             'filename': 'Lines_Not_Imported.xls',
                                             'message': """%s %s""" % (GENERIC_MESSAGE, ', '.join([_(f) for f in cols])),
                                             'rule_id': ids[0],
                                             'state': 'draft',}, context=context)

        return {'type': 'ir.actions.act_window',
                'res_model': 'wizard.import.order.cycle.line',
                'res_id': export_id,
                'view_type': 'form',
                'view_mode': 'form',
                'target': 'crush',
                'context': context,
                }

order_cycle_rule()

class threshold_value_rule(osv.osv):
    """
    We override the class for import of Threshold value rule lines
    """
    _inherit = 'threshold.value'

    def wizard_import_threshold_value_line(self, cr, uid, ids, context=None):
        '''
        Launches the wizard to import lines from a file
        '''
        # Objects
        wiz_obj = self.pool.get('wizard.import.threshold.value.line')

        context = context is None and {} or context

        if isinstance(ids, (int, long)):
            ids = [ids]

        context.update({'active_id': ids[0]})

        rule = self.browse(cr, uid, ids[0], context=context)
        header_cols = columns_header_for_threshold
        cols = columns_for_threshold

        columns_header = [(_(f[0]), f[1]) for f in header_cols]
        default_template = SpreadsheetCreator(_('Template of import'), columns_header, [])
        file = base64.encodestring(default_template.get_xml(default_filters=['decode.utf8']))
        export_id = wiz_obj.create(cr, uid, {'file': file,
                                             'filename_template': 'Threshold value template.xls',
                                             'filename': 'Lines_Not_Imported.xls',
                                             'message': """%s %s""" % (GENERIC_MESSAGE, ', '.join([_(f) for f in cols])),
                                             'rule_id': ids[0],
                                             'state': 'draft',}, context=context)

        return {'type': 'ir.actions.act_window',
                'res_model': 'wizard.import.threshold.value.line',
                'res_id': export_id,
                'view_type': 'form',
                'view_mode': 'form',
                'target': 'crush',
                'context': context,
                }

threshold_value_rule()