Merge lp:~akretion-team/openerp-product-variant/product-variant-multi-attribute into lp:openerp-product-variant/trunk
- product-variant-multi-attribute
- Merge into extraction-70
Status: | Needs review |
---|---|
Proposed branch: | lp:~akretion-team/openerp-product-variant/product-variant-multi-attribute |
Merge into: | lp:openerp-product-variant/trunk |
Diff against target: |
2965 lines (+1659/-870) 32 files modified
__unported__/product_variant_multi_advanced/__openerp__.py (+1/-1) __unported__/product_variant_multi_advanced/product.py (+5/-5) product_display/__init__.py (+23/-0) product_display/__openerp__.py (+49/-0) product_display/product.py (+47/-0) product_display/product_view.xml (+28/-0) product_variant_display_generator/__init__.py (+23/-0) product_variant_display_generator/__openerp__.py (+45/-0) product_variant_display_generator/product_variant_display.py (+130/-0) product_variant_display_generator/product_view.xml (+44/-0) product_variant_generator/__init__.py (+1/-0) product_variant_generator/__openerp__.py (+8/-6) product_variant_generator/product_data.xml (+29/-0) product_variant_generator/product_variant.py (+455/-516) product_variant_generator/product_view.xml (+97/-252) product_variant_generator/security/ir.model.access.csv (+2/-6) product_variant_generator/wizard/__init__.py (+24/-0) product_variant_generator/wizard/product_template_add_option.py (+69/-0) product_variant_generator/wizard/product_template_add_option_view.xml (+29/-0) product_variant_generator_price/__init__.py (+23/-0) product_variant_generator_price/__openerp__.py (+40/-0) product_variant_generator_price/product_variant.py (+119/-0) product_variant_generator_price/product_view.xml (+79/-0) product_variant_multi/demo_data.xml (+0/-84) product_variant_simple/__init__.py (+3/-0) product_variant_simple/__openerp__.py (+47/-0) product_variant_simple/product.py (+32/-0) product_variant_simple/product_view.xml (+92/-0) product_variant_simple/security/security.xml (+13/-0) sale_product_display/__init__.py (+23/-0) sale_product_display/__openerp__.py (+40/-0) sale_product_display/sale.py (+39/-0) |
To merge this branch: | bzr merge lp:~akretion-team/openerp-product-variant/product-variant-multi-attribute |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexandre Fayolle - camptocamp | Needs Resubmitting | ||
Review via email: mp+223611@code.launchpad.net |
Commit message
Description of the change
It's a total refactor of product variant multi.
The idea is too split the module in order to be more flexible.
As you can see a new concept have been added "Product display", this are the equivalent of "Configurable Product" on Magento side.
We do not map the "Product Template" with "Configurable Product" because it's not the same concept. Template are here for generating all of the variant, and the "Product Display" is just a way to show your product in a catalog.
For example, you can have 1 template (t-shirt color: red/yellow/blue size:S/M/L/XL) and then on magento you want to create 3 configurables products, one for each color. this case can be supported as you will create 3 displays from the product template.
- 249. By Sébastien BEAU - http://www.akretion.com
-
[FIX] add missing file data for having 2 default template for code/name
- 250. By Chafique DELLI
-
[REF] refactor module product_
variant_ generator_ price
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote : | # |
Unmerged revisions
- 250. By Chafique DELLI
-
[REF] refactor module product_
variant_ generator_ price - 249. By Sébastien BEAU - http://www.akretion.com
-
[FIX] add missing file data for having 2 default template for code/name
- 248. By Sébastien BEAU - http://www.akretion.com
-
[CLEAN] pep8 clean up
- 247. By Sébastien BEAU - http://www.akretion.com
-
[REF] refactor module as product.
variant. dimension have been removed - 246. By Sébastien BEAU - http://www.akretion.com
-
[CLEAN] pep8 clean up
- 245. By Sébastien BEAU - http://www.akretion.com
-
[REF] rename generate_
display_ from_dim_ id into main_dim_id - 244. By Sébastien BEAU - http://www.akretion.com
-
[CLEAN] pep8 clean up
- 243. By Sébastien BEAU - http://www.akretion.com
-
[REF] refactor product template code/name generation. Now you can create template generator and use/share it
- 242. By Sébastien BEAU - http://www.akretion.com
-
[REF] UI refactor, having the dimension is too much as we already have the attribute set
- 241. By Sébastien BEAU - http://www.akretion.com
-
[CLEAN] pep8 clean up
Preview Diff
1 | === added directory '__unported__' | |||
2 | === renamed directory 'product_variant_multi_advanced' => '__unported__/product_variant_multi_advanced' | |||
3 | === modified file '__unported__/product_variant_multi_advanced/__openerp__.py' | |||
4 | --- product_variant_multi_advanced/__openerp__.py 2013-09-19 11:46:57 +0000 | |||
5 | +++ __unported__/product_variant_multi_advanced/__openerp__.py 2014-06-24 09:37:35 +0000 | |||
6 | @@ -39,6 +39,6 @@ | |||
7 | 39 | 'init_xml': [], | 39 | 'init_xml': [], |
8 | 40 | 'update_xml': ['product.xml'], | 40 | 'update_xml': ['product.xml'], |
9 | 41 | 'demo_xml': [], | 41 | 'demo_xml': [], |
11 | 42 | 'installable': True, | 42 | 'installable': False, |
12 | 43 | 'active': False, | 43 | 'active': False, |
13 | 44 | } | 44 | } |
14 | 45 | 45 | ||
15 | === modified file '__unported__/product_variant_multi_advanced/product.py' | |||
16 | --- product_variant_multi_advanced/product.py 2013-09-19 15:50:40 +0000 | |||
17 | +++ __unported__/product_variant_multi_advanced/product.py 2014-06-24 09:37:35 +0000 | |||
18 | @@ -41,13 +41,13 @@ | |||
19 | 41 | duplicated_fields = ['description_sale', 'name'] | 41 | duplicated_fields = ['description_sale', 'name'] |
20 | 42 | 42 | ||
21 | 43 | 43 | ||
23 | 44 | class product_template(orm.Model): | 44 | class ProductTemplate(orm.Model): |
24 | 45 | _inherit = "product.template" | 45 | _inherit = "product.template" |
25 | 46 | 46 | ||
26 | 47 | def button_generate_variants(self, cr, uid, ids, context=None): | 47 | def button_generate_variants(self, cr, uid, ids, context=None): |
27 | 48 | if context is None: | 48 | if context is None: |
28 | 49 | context = {} | 49 | context = {} |
30 | 50 | super(product_template, self).button_generate_variants(cr, uid, ids, context=context) | 50 | super(ProductTemplate, self).button_generate_variants(cr, uid, ids, context=context) |
31 | 51 | product_ids = self.get_products_from_product_template(cr, uid, ids, context=context) | 51 | product_ids = self.get_products_from_product_template(cr, uid, ids, context=context) |
32 | 52 | # generate/update sale description | 52 | # generate/update sale description |
33 | 53 | _logger.info("Starting to generate/update product sale descriptions...") | 53 | _logger.info("Starting to generate/update product sale descriptions...") |
34 | @@ -57,7 +57,7 @@ | |||
35 | 57 | return True | 57 | return True |
36 | 58 | 58 | ||
37 | 59 | 59 | ||
39 | 60 | class product_product(orm.Model): | 60 | class ProductProduct(orm.Model): |
40 | 61 | _inherit = "product.product" | 61 | _inherit = "product.product" |
41 | 62 | 62 | ||
42 | 63 | def write(self, cr, uid, ids, vals, context=None): | 63 | def write(self, cr, uid, ids, vals, context=None): |
43 | @@ -65,7 +65,7 @@ | |||
44 | 65 | ids = [ids] | 65 | ids = [ids] |
45 | 66 | if context is None: | 66 | if context is None: |
46 | 67 | context = {} | 67 | context = {} |
48 | 68 | res = super(product_product, self).write(cr, uid, ids, vals.copy(), context=context) | 68 | res = super(ProductProduct, self).write(cr, uid, ids, vals.copy(), context=context) |
49 | 69 | 69 | ||
50 | 70 | ids_simple = self.search( | 70 | ids_simple = self.search( |
51 | 71 | cr, uid, | 71 | cr, uid, |
52 | @@ -98,7 +98,7 @@ | |||
53 | 98 | # and not on the product_product | 98 | # and not on the product_product |
54 | 99 | 99 | ||
55 | 100 | #take care to use vals.copy() if not the vals will be changed by calling the super method | 100 | #take care to use vals.copy() if not the vals will be changed by calling the super method |
57 | 101 | ids = super(product_product, self).create(cr, uid, vals.copy(), context=context) | 101 | ids = super(ProductProduct, self).create(cr, uid, vals.copy(), context=context) |
58 | 102 | ####### write the value in the product_product | 102 | ####### write the value in the product_product |
59 | 103 | ctx = context.copy() | 103 | ctx = context.copy() |
60 | 104 | ctx['iamthechild'] = True | 104 | ctx['iamthechild'] = True |
61 | 105 | 105 | ||
62 | === added directory 'product_display' | |||
63 | === added file 'product_display/__init__.py' | |||
64 | --- product_display/__init__.py 1970-01-01 00:00:00 +0000 | |||
65 | +++ product_display/__init__.py 2014-06-24 09:37:35 +0000 | |||
66 | @@ -0,0 +1,23 @@ | |||
67 | 1 | # -*- coding: utf-8 -*- | ||
68 | 2 | ############################################################################### | ||
69 | 3 | # | ||
70 | 4 | # Module for OpenERP | ||
71 | 5 | # Copyright (C) 2013 Akretion (http://www.akretion.com). | ||
72 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
73 | 7 | # | ||
74 | 8 | # This program is free software: you can redistribute it and/or modify | ||
75 | 9 | # it under the terms of the GNU Affero General Public License as | ||
76 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
77 | 11 | # License, or (at your option) any later version. | ||
78 | 12 | # | ||
79 | 13 | # This program is distributed in the hope that it will be useful, | ||
80 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
81 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
82 | 16 | # GNU Affero General Public License for more details. | ||
83 | 17 | # | ||
84 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
85 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
86 | 20 | # | ||
87 | 21 | ############################################################################### | ||
88 | 22 | |||
89 | 23 | import product | ||
90 | 0 | 24 | ||
91 | === added file 'product_display/__openerp__.py' | |||
92 | --- product_display/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
93 | +++ product_display/__openerp__.py 2014-06-24 09:37:35 +0000 | |||
94 | @@ -0,0 +1,49 @@ | |||
95 | 1 | # -*- coding: utf-8 -*- | ||
96 | 2 | ############################################################################## | ||
97 | 3 | # | ||
98 | 4 | # Author: Chafique Delli | ||
99 | 5 | # Copyright 2013 Akretion | ||
100 | 6 | # | ||
101 | 7 | # This program is free software: you can redistribute it and/or modify | ||
102 | 8 | # it under the terms of the GNU Affero General Public License as | ||
103 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
104 | 10 | # License, or (at your option) any later version. | ||
105 | 11 | # | ||
106 | 12 | # This program is distributed in the hope that it will be useful, | ||
107 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
108 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
109 | 15 | # GNU Affero General Public License for more details. | ||
110 | 16 | # | ||
111 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
112 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
113 | 19 | # | ||
114 | 20 | ############################################################################## | ||
115 | 21 | {'name' : 'Product Display', | ||
116 | 22 | 'version' : '1.0', | ||
117 | 23 | "author": "Akretion", | ||
118 | 24 | 'category': 'Sales Management', | ||
119 | 25 | 'description': """ | ||
120 | 26 | Product Display | ||
121 | 27 | ================ | ||
122 | 28 | |||
123 | 29 | A simple module for handling the product display. | ||
124 | 30 | It provides view for product display, | ||
125 | 31 | so they can be created manually. It doesn't provide | ||
126 | 32 | all the bells and whistles of the product_variant_display | ||
127 | 33 | module (creator wizards, ...). | ||
128 | 34 | |||
129 | 35 | """, | ||
130 | 36 | 'author' : 'Akretion', | ||
131 | 37 | 'maintainer': 'Akretion', | ||
132 | 38 | 'website': 'http://www.akretion.com/', | ||
133 | 39 | 'depends' : [ | ||
134 | 40 | 'product', | ||
135 | 41 | ], | ||
136 | 42 | 'data': [ | ||
137 | 43 | 'product_view.xml', | ||
138 | 44 | ], | ||
139 | 45 | 'test': [], | ||
140 | 46 | 'installable': True, | ||
141 | 47 | 'auto_install': False, | ||
142 | 48 | 'application': True, | ||
143 | 49 | } | ||
144 | 0 | 50 | ||
145 | === added file 'product_display/product.py' | |||
146 | --- product_display/product.py 1970-01-01 00:00:00 +0000 | |||
147 | +++ product_display/product.py 2014-06-24 09:37:35 +0000 | |||
148 | @@ -0,0 +1,47 @@ | |||
149 | 1 | # -*- coding: utf-8 -*- | ||
150 | 2 | ############################################################################### | ||
151 | 3 | # | ||
152 | 4 | # Module for OpenERP | ||
153 | 5 | # Copyright (C) 2013 Akretion (http://www.akretion.com). | ||
154 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
155 | 7 | # | ||
156 | 8 | # This program is free software: you can redistribute it and/or modify | ||
157 | 9 | # it under the terms of the GNU Affero General Public License as | ||
158 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
159 | 11 | # License, or (at your option) any later version. | ||
160 | 12 | # | ||
161 | 13 | # This program is distributed in the hope that it will be useful, | ||
162 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
163 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
164 | 16 | # GNU Affero General Public License for more details. | ||
165 | 17 | # | ||
166 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
167 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
168 | 20 | # | ||
169 | 21 | ############################################################################### | ||
170 | 22 | |||
171 | 23 | from openerp.osv import orm, fields | ||
172 | 24 | |||
173 | 25 | |||
174 | 26 | class ProductProduct(orm.Model): | ||
175 | 27 | _inherit = 'product.product' | ||
176 | 28 | |||
177 | 29 | _columns = { | ||
178 | 30 | 'display_for_product_ids': fields.many2many( | ||
179 | 31 | 'product.product', | ||
180 | 32 | 'product_template_option_rel', | ||
181 | 33 | 'product_display_id', | ||
182 | 34 | 'product_id', | ||
183 | 35 | string='Products'), | ||
184 | 36 | 'display_ids': fields.many2many( | ||
185 | 37 | 'product.product', | ||
186 | 38 | 'product_template_option_rel', | ||
187 | 39 | 'product_id', | ||
188 | 40 | 'product_display_id', | ||
189 | 41 | string='Products Display'), | ||
190 | 42 | 'is_display': fields.boolean('Is Display'), | ||
191 | 43 | } | ||
192 | 44 | |||
193 | 45 | _defaults = { | ||
194 | 46 | 'is_display': False, | ||
195 | 47 | } | ||
196 | 0 | 48 | ||
197 | === added file 'product_display/product_view.xml' | |||
198 | --- product_display/product_view.xml 1970-01-01 00:00:00 +0000 | |||
199 | +++ product_display/product_view.xml 2014-06-24 09:37:35 +0000 | |||
200 | @@ -0,0 +1,28 @@ | |||
201 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
202 | 2 | <openerp> | ||
203 | 3 | <data> | ||
204 | 4 | |||
205 | 5 | |||
206 | 6 | <!--Product Display --> | ||
207 | 7 | |||
208 | 8 | <record id="product_display_form_view" model="ir.ui.view"> | ||
209 | 9 | <field name="name">product.display.form</field> | ||
210 | 10 | <field name="model">product.product</field> | ||
211 | 11 | <field name="inherit_id" ref="product.product_normal_form_view" /> | ||
212 | 12 | <field name="arch" type="xml"> | ||
213 | 13 | <xpath expr="//label[@for='sale_ok']" position="after"> | ||
214 | 14 | <field name="is_display"/> | ||
215 | 15 | <label for="is_display" /> | ||
216 | 16 | </xpath> | ||
217 | 17 | <notebook position="inside"> | ||
218 | 18 | <page string="Product Display" attrs="{'invisible':[('is_display','=',False)]}"> | ||
219 | 19 | <group colspan="2" col="2"> | ||
220 | 20 | <field name="display_for_product_ids" nolabel="1"/> | ||
221 | 21 | </group> | ||
222 | 22 | </page> | ||
223 | 23 | </notebook> | ||
224 | 24 | </field> | ||
225 | 25 | </record> | ||
226 | 26 | |||
227 | 27 | </data> | ||
228 | 28 | </openerp> | ||
229 | 0 | 29 | ||
230 | === added directory 'product_variant_display_generator' | |||
231 | === added file 'product_variant_display_generator/__init__.py' | |||
232 | --- product_variant_display_generator/__init__.py 1970-01-01 00:00:00 +0000 | |||
233 | +++ product_variant_display_generator/__init__.py 2014-06-24 09:37:35 +0000 | |||
234 | @@ -0,0 +1,23 @@ | |||
235 | 1 | # -*- coding: utf-8 -*- | ||
236 | 2 | ############################################################################### | ||
237 | 3 | # | ||
238 | 4 | # Module for OpenERP | ||
239 | 5 | # Copyright (C) 2013 Akretion (http://www.akretion.com). | ||
240 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
241 | 7 | # | ||
242 | 8 | # This program is free software: you can redistribute it and/or modify | ||
243 | 9 | # it under the terms of the GNU Affero General Public License as | ||
244 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
245 | 11 | # License, or (at your option) any later version. | ||
246 | 12 | # | ||
247 | 13 | # This program is distributed in the hope that it will be useful, | ||
248 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
249 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
250 | 16 | # GNU Affero General Public License for more details. | ||
251 | 17 | # | ||
252 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
253 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
254 | 20 | # | ||
255 | 21 | ############################################################################### | ||
256 | 22 | |||
257 | 23 | import product_variant_display | ||
258 | 0 | 24 | ||
259 | === added file 'product_variant_display_generator/__openerp__.py' | |||
260 | --- product_variant_display_generator/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
261 | +++ product_variant_display_generator/__openerp__.py 2014-06-24 09:37:35 +0000 | |||
262 | @@ -0,0 +1,45 @@ | |||
263 | 1 | # -*- coding: utf-8 -*- | ||
264 | 2 | ############################################################################### | ||
265 | 3 | # | ||
266 | 4 | # Module for OpenERP | ||
267 | 5 | # Copyright (C) 2013 Akretion (http://www.akretion.com). | ||
268 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
269 | 7 | # | ||
270 | 8 | # This program is free software: you can redistribute it and/or modify | ||
271 | 9 | # it under the terms of the GNU Affero General Public License as | ||
272 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
273 | 11 | # License, or (at your option) any later version. | ||
274 | 12 | # | ||
275 | 13 | # This program is distributed in the hope that it will be useful, | ||
276 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
277 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
278 | 16 | # GNU Affero General Public License for more details. | ||
279 | 17 | # | ||
280 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
281 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
282 | 20 | # | ||
283 | 21 | ############################################################################### | ||
284 | 22 | { | ||
285 | 23 | "name": "Product Variant Display Generator", | ||
286 | 24 | "version": "1.0", | ||
287 | 25 | "author": "OpenERP SA, Akretion", | ||
288 | 26 | "category": "Sales Management", | ||
289 | 27 | "license": "AGPL-3", | ||
290 | 28 | "summary": "Products Displays with multi-dimension variants ", | ||
291 | 29 | "description": """ | ||
292 | 30 | Multi-axial display product support for OpenERP | ||
293 | 31 | =============================================== | ||
294 | 32 | |||
295 | 33 | |||
296 | 34 | """, | ||
297 | 35 | "depends" : [ | ||
298 | 36 | "product_custom_attributes", | ||
299 | 37 | "product_variant_generator", | ||
300 | 38 | "product_display" | ||
301 | 39 | ], | ||
302 | 40 | "data" : ["product_view.xml", | ||
303 | 41 | ], | ||
304 | 42 | "application": True, | ||
305 | 43 | "active": False, | ||
306 | 44 | "installable": True, | ||
307 | 45 | } | ||
308 | 0 | 46 | ||
309 | === added file 'product_variant_display_generator/product_variant_display.py' | |||
310 | --- product_variant_display_generator/product_variant_display.py 1970-01-01 00:00:00 +0000 | |||
311 | +++ product_variant_display_generator/product_variant_display.py 2014-06-24 09:37:35 +0000 | |||
312 | @@ -0,0 +1,130 @@ | |||
313 | 1 | # -*- coding: utf-8 -*- | ||
314 | 2 | ############################################################################### | ||
315 | 3 | # | ||
316 | 4 | # Module for OpenERP | ||
317 | 5 | # Copyright (C) 2013 Akretion (http://www.akretion.com). | ||
318 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
319 | 7 | # | ||
320 | 8 | # This program is free software: you can redistribute it and/or modify | ||
321 | 9 | # it under the terms of the GNU Affero General Public License as | ||
322 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
323 | 11 | # License, or (at your option) any later version. | ||
324 | 12 | # | ||
325 | 13 | # This program is distributed in the hope that it will be useful, | ||
326 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
327 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
328 | 16 | # GNU Affero General Public License for more details. | ||
329 | 17 | # | ||
330 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
331 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
332 | 20 | # | ||
333 | 21 | ############################################################################### | ||
334 | 22 | |||
335 | 23 | from openerp.osv import orm, fields | ||
336 | 24 | |||
337 | 25 | |||
338 | 26 | import logging | ||
339 | 27 | _logger = logging.getLogger(__name__) | ||
340 | 28 | |||
341 | 29 | |||
342 | 30 | class ProductTemplate(orm.Model): | ||
343 | 31 | _inherit = "product.template" | ||
344 | 32 | |||
345 | 33 | _columns = { | ||
346 | 34 | 'generate_main_display': fields.boolean('Generate Main Display'), | ||
347 | 35 | 'main_dim_id': fields.many2one( | ||
348 | 36 | 'attribute.attribute', | ||
349 | 37 | string='Main Dimension', | ||
350 | 38 | help=('This dimension will be used for generating ' | ||
351 | 39 | 'the product display')), | ||
352 | 40 | 'display_variant_ids': fields.one2many( | ||
353 | 41 | 'product.product', | ||
354 | 42 | 'product_tmpl_id', | ||
355 | 43 | domain=[ | ||
356 | 44 | ('is_display', '=', True), | ||
357 | 45 | '|', | ||
358 | 46 | ('active', '=', True), | ||
359 | 47 | ('active', '=', False), | ||
360 | 48 | ], string='Display Variants'), | ||
361 | 49 | 'product_variant_ids': fields.one2many( | ||
362 | 50 | 'product.product', | ||
363 | 51 | 'product_tmpl_id', | ||
364 | 52 | domain=[ | ||
365 | 53 | ('is_display', '=', False), | ||
366 | 54 | '|', | ||
367 | 55 | ('active', '=', True), | ||
368 | 56 | ('active', '=', False), | ||
369 | 57 | ], string='Product Variants'), | ||
370 | 58 | } | ||
371 | 59 | |||
372 | 60 | def _get_combinaison(self, cr, uid, product_temp, context=None): | ||
373 | 61 | if context.get('product_display'): | ||
374 | 62 | fields = [dim.name for dim in product_temp.dimension_ids] | ||
375 | 63 | num_of_fields = len(fields) | ||
376 | 64 | combinaisons = [] | ||
377 | 65 | if product_temp.main_dim_id: | ||
378 | 66 | for value in product_temp.value_ids: | ||
379 | 67 | if value.dimension_id.id == product_temp.main_dim_id.id: | ||
380 | 68 | combinaisons.append( | ||
381 | 69 | [value.option_id.id] + [None]*(num_of_fields - 1) | ||
382 | 70 | ) | ||
383 | 71 | if product_temp.generate_main_display: | ||
384 | 72 | combinaisons.append([None]*num_of_fields) | ||
385 | 73 | return combinaisons | ||
386 | 74 | return super(ProductTemplate, self)._get_combinaison( | ||
387 | 75 | cr, uid, product_temp, context=context) | ||
388 | 76 | |||
389 | 77 | def _prepare_variant_vals(self, cr, uid, product_temp, combinaison, | ||
390 | 78 | context=None): | ||
391 | 79 | product_obj = self.pool['product.product'] | ||
392 | 80 | vals = super(ProductTemplate, self)._prepare_variant_vals( | ||
393 | 81 | cr, uid, product_temp, combinaison, context=context) | ||
394 | 82 | if context.get('product_display'): | ||
395 | 83 | vals['is_display'] = True | ||
396 | 84 | domain = [ | ||
397 | 85 | ['product_tmpl_id', '=', vals['product_tmpl_id']], | ||
398 | 86 | ['is_display', '=', False], | ||
399 | 87 | ] | ||
400 | 88 | dimension = product_temp.main_dim_id | ||
401 | 89 | if dimension and dimension.name in vals: | ||
402 | 90 | domain.append([dimension.name, '=', vals[dimension.name]]) | ||
403 | 91 | product_ids = product_obj.search(cr, uid, domain, context=context) | ||
404 | 92 | vals['display_for_product_ids'] = [(6, 0, product_ids)] | ||
405 | 93 | return vals | ||
406 | 94 | |||
407 | 95 | def _create_variant(self, cr, uid, product_temp, existing_product_ids, | ||
408 | 96 | context=None): | ||
409 | 97 | created_product_ids = super(ProductTemplate, self)._create_variant( | ||
410 | 98 | cr, uid, product_temp, existing_product_ids, context=context) | ||
411 | 99 | if created_product_ids: | ||
412 | 100 | self.pool['product.product'].update_existing_product_display( | ||
413 | 101 | cr, uid, created_product_ids, context=context) | ||
414 | 102 | |||
415 | 103 | ctx = context.copy() | ||
416 | 104 | ctx['product_display'] = True | ||
417 | 105 | created_product_display_ids = super(ProductTemplate, self).\ | ||
418 | 106 | _create_variant(cr, uid, product_temp, existing_product_ids, | ||
419 | 107 | context=ctx) | ||
420 | 108 | return created_product_ids + created_product_display_ids | ||
421 | 109 | |||
422 | 110 | |||
423 | 111 | class ProductProduct(orm.Model): | ||
424 | 112 | _inherit = 'product.product' | ||
425 | 113 | |||
426 | 114 | def update_existing_product_display(self, cr, uid, ids, context=None): | ||
427 | 115 | ids = self.search(cr, uid, [ | ||
428 | 116 | ['id', 'in', ids], | ||
429 | 117 | ['is_display', '=', True] | ||
430 | 118 | ], context=context) | ||
431 | 119 | |||
432 | 120 | for product in self.browse(cr, uid, ids, context=context): | ||
433 | 121 | domain = [ | ||
434 | 122 | ['product_tmpl_id', '=', product.product_tmpl_id.id], | ||
435 | 123 | ['is_display', '=', False], | ||
436 | 124 | ] | ||
437 | 125 | dim = product.main_dim_id | ||
438 | 126 | if dim and product[dim.name]: | ||
439 | 127 | domain.append([dim.name, '=', product[dim.name].name]) | ||
440 | 128 | product_ids = self.search(cr, uid, domain, context=context) | ||
441 | 129 | product.write({'display_for_product_ids': [(6, 0, product_ids)]}) | ||
442 | 130 | return True | ||
443 | 0 | 131 | ||
444 | === added file 'product_variant_display_generator/product_view.xml' | |||
445 | --- product_variant_display_generator/product_view.xml 1970-01-01 00:00:00 +0000 | |||
446 | +++ product_variant_display_generator/product_view.xml 2014-06-24 09:37:35 +0000 | |||
447 | @@ -0,0 +1,44 @@ | |||
448 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
449 | 2 | <openerp> | ||
450 | 3 | <data> | ||
451 | 4 | |||
452 | 5 | <!-- | ||
453 | 6 | Module for OpenERP | ||
454 | 7 | The licence is in the file __openerp__.py | ||
455 | 8 | @author Chafique Delli <chafique.delli@akretion.com> | ||
456 | 9 | --> | ||
457 | 10 | |||
458 | 11 | <!-- PRODUCT TEMPLATE --> | ||
459 | 12 | <record id="product_variant_multi_product_display_form_view" model="ir.ui.view"> | ||
460 | 13 | <field name="name">product.variant.multi.product.display.form</field> | ||
461 | 14 | <field name="model">product.template</field> | ||
462 | 15 | <field name="inherit_id" ref="product_variant_generator.product_variant_multi_product_template_form_view" /> | ||
463 | 16 | <field name="arch" type="xml"> | ||
464 | 17 | <xpath expr="//field[@name='do_not_update_variant']/.." position="after"> | ||
465 | 18 | <group string="Displays" colspan="1" col="4" attrs="{'invisible':[('is_multi_variants','=',False)]}"> | ||
466 | 19 | <field name="generate_main_display"/> | ||
467 | 20 | <field name="dimension_ids" invisible="1"/> | ||
468 | 21 | <field name="main_dim_id" domain="[('id', 'in', dimension_ids and dimension_ids[0][2])]"/> | ||
469 | 22 | <field name="display_variant_ids" nolabel="1" colspan="4"> | ||
470 | 23 | <tree string="Display Variants"> | ||
471 | 24 | <field name="code" /> | ||
472 | 25 | <field name="name" /> | ||
473 | 26 | <field name="variants" string="Dimension Values" /> | ||
474 | 27 | </tree> | ||
475 | 28 | </field> | ||
476 | 29 | </group> | ||
477 | 30 | </xpath> | ||
478 | 31 | <field name="variant_ids" position="replace"> | ||
479 | 32 | <field name="product_variant_ids" nolabel="1" colspan="4"> | ||
480 | 33 | <tree string="Product Variants"> | ||
481 | 34 | <field name="code" /> | ||
482 | 35 | <field name="name" /> | ||
483 | 36 | <field name="variants" string="Dimension Values" /> | ||
484 | 37 | </tree> | ||
485 | 38 | </field> | ||
486 | 39 | </field> | ||
487 | 40 | </field> | ||
488 | 41 | </record> | ||
489 | 42 | |||
490 | 43 | </data> | ||
491 | 44 | </openerp> | ||
492 | 0 | 45 | ||
493 | === renamed directory 'product_variant_multi' => 'product_variant_generator' | |||
494 | === modified file 'product_variant_generator/__init__.py' | |||
495 | --- product_variant_multi/__init__.py 2013-09-19 11:46:57 +0000 | |||
496 | +++ product_variant_generator/__init__.py 2014-06-24 09:37:35 +0000 | |||
497 | @@ -22,3 +22,4 @@ | |||
498 | 22 | # flake8: noqa | 22 | # flake8: noqa |
499 | 23 | 23 | ||
500 | 24 | from . import product_variant | 24 | from . import product_variant |
501 | 25 | from . import wizard | ||
502 | 25 | 26 | ||
503 | === modified file 'product_variant_generator/__openerp__.py' | |||
504 | --- product_variant_multi/__openerp__.py 2013-09-19 11:46:57 +0000 | |||
505 | +++ product_variant_generator/__openerp__.py 2014-06-24 09:37:35 +0000 | |||
506 | @@ -20,7 +20,7 @@ | |||
507 | 20 | # | 20 | # |
508 | 21 | ############################################################################## | 21 | ############################################################################## |
509 | 22 | { | 22 | { |
511 | 23 | "name": "Product Variant Multi", | 23 | "name": "Product Variant Generator", |
512 | 24 | "version": "1.0", | 24 | "version": "1.0", |
513 | 25 | "author": "OpenERP SA, Akretion", | 25 | "author": "OpenERP SA, Akretion", |
514 | 26 | "category": "Sales Management", | 26 | "category": "Sales Management", |
515 | @@ -44,8 +44,6 @@ | |||
516 | 44 | the space of the variants. You could also choose to populate only some combinations | 44 | the space of the variants. You could also choose to populate only some combinations |
517 | 45 | by hand instead. | 45 | by hand instead. |
518 | 46 | 46 | ||
519 | 47 | Each variant can have an extra price that will be taken into account when computing | ||
520 | 48 | the base listed price. Yet to be implemented: a price extra per variant dimension value. | ||
521 | 49 | Finally, this module is better used along with the product_variant_configurator which | 47 | Finally, this module is better used along with the product_variant_configurator which |
522 | 50 | will help the salesman selecting the appropriate variant in the sale order line | 48 | will help the salesman selecting the appropriate variant in the sale order line |
523 | 51 | using dimension criteria instead of having to crawl the full space of variants. | 49 | using dimension criteria instead of having to crawl the full space of variants. |
524 | @@ -60,11 +58,15 @@ | |||
525 | 60 | and only from product.template if not found on product.product. But at least you | 58 | and only from product.template if not found on product.product. But at least you |
526 | 61 | will have been warned. | 59 | will have been warned. |
527 | 62 | """, | 60 | """, |
531 | 63 | "depends": ["product"], | 61 | "depends" : [ |
532 | 64 | "demo": ["demo_data.xml"], | 62 | "product_custom_attributes", |
533 | 65 | "data": [ | 63 | "product_variant_simple" |
534 | 64 | ], | ||
535 | 65 | "data" : [ | ||
536 | 66 | "wizard/product_template_add_option_view.xml", | ||
537 | 66 | "security/ir.model.access.csv", | 67 | "security/ir.model.access.csv", |
538 | 67 | "product_view.xml", | 68 | "product_view.xml", |
539 | 69 | "product_data.xml", | ||
540 | 68 | ], | 70 | ], |
541 | 69 | "application": True, | 71 | "application": True, |
542 | 70 | "active": False, | 72 | "active": False, |
543 | 71 | 73 | ||
544 | === added file 'product_variant_generator/product_data.xml' | |||
545 | --- product_variant_generator/product_data.xml 1970-01-01 00:00:00 +0000 | |||
546 | +++ product_variant_generator/product_data.xml 2014-06-24 09:37:35 +0000 | |||
547 | @@ -0,0 +1,29 @@ | |||
548 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
549 | 2 | <openerp> | ||
550 | 3 | <data noupdate="0"> | ||
551 | 4 | |||
552 | 5 | <record id="product_name_generator" model="string.template"> | ||
553 | 6 | <field name="name">Default Name Generator</field> | ||
554 | 7 | <field name="type">product_name</field> | ||
555 | 8 | <field name="code">name = [] | ||
556 | 9 | for dimension in o.dimension_ids: | ||
557 | 10 | if o[dimension.name].name: | ||
558 | 11 | name.append("%s - %s" %(dimension.field_description, o[dimension.name].name)) | ||
559 | 12 | result = " | ".join(name)</field> | ||
560 | 13 | </record> | ||
561 | 14 | |||
562 | 15 | <record id="product_code_generator" model="string.template"> | ||
563 | 16 | <field name="name">Default Code Generator</field> | ||
564 | 17 | <field name="type">product_code</field> | ||
565 | 18 | <field name="code">code = [] | ||
566 | 19 | if o.base_default_code: | ||
567 | 20 | code.append(o.base_default_code) | ||
568 | 21 | for dimension in o.dimension_ids: | ||
569 | 22 | if o[dimension.name].name: | ||
570 | 23 | code.append(o[dimension.name].name) | ||
571 | 24 | result = " - ".join(code)</field> | ||
572 | 25 | </record> | ||
573 | 26 | |||
574 | 27 | </data> | ||
575 | 28 | </openerp> | ||
576 | 29 | |||
577 | 0 | 30 | ||
578 | === modified file 'product_variant_generator/product_variant.py' | |||
579 | --- product_variant_multi/product_variant.py 2013-09-19 15:50:40 +0000 | |||
580 | +++ product_variant_generator/product_variant.py 2014-06-24 09:37:35 +0000 | |||
581 | @@ -7,6 +7,7 @@ | |||
582 | 7 | # @author Sebatien Beau <sebastien.beau@akretion.com> | 7 | # @author Sebatien Beau <sebastien.beau@akretion.com> |
583 | 8 | # @author Raphaël Valyi <raphael.valyi@akretion.com> | 8 | # @author Raphaël Valyi <raphael.valyi@akretion.com> |
584 | 9 | # @author Alexis de Lattre <alexis.delattre@akretion.com> | 9 | # @author Alexis de Lattre <alexis.delattre@akretion.com> |
585 | 10 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
586 | 10 | # update to use a single "Generate/Update" button & price computation code | 11 | # update to use a single "Generate/Update" button & price computation code |
587 | 11 | # | 12 | # |
588 | 12 | # This program is free software: you can redistribute it and/or modify | 13 | # This program is free software: you can redistribute it and/or modify |
589 | @@ -25,215 +26,308 @@ | |||
590 | 25 | ############################################################################## | 26 | ############################################################################## |
591 | 26 | 27 | ||
592 | 27 | from openerp.osv import fields, osv, orm | 28 | from openerp.osv import fields, osv, orm |
593 | 28 | import openerp.addons.decimal_precision as dp | ||
594 | 29 | # Lib to eval python code with security | 29 | # Lib to eval python code with security |
595 | 30 | from openerp.tools.translate import _ | ||
596 | 31 | from collections import defaultdict | ||
597 | 32 | from openerp.tools import config | ||
598 | 30 | from openerp.tools.safe_eval import safe_eval | 33 | from openerp.tools.safe_eval import safe_eval |
600 | 31 | from openerp.tools.translate import _ | 34 | import datetime |
601 | 35 | |||
602 | 32 | 36 | ||
603 | 33 | import logging | 37 | import logging |
604 | 34 | _logger = logging.getLogger(__name__) | 38 | _logger = logging.getLogger(__name__) |
605 | 35 | 39 | ||
606 | 36 | 40 | ||
610 | 37 | class product_variant_dimension_type(orm.Model): | 41 | class AttributeAttribute(orm.Model): |
611 | 38 | _name = "product.variant.dimension.type" | 42 | _inherit = 'attribute.attribute' |
609 | 39 | _description = "Dimension Type" | ||
612 | 40 | 43 | ||
613 | 41 | _columns = { | 44 | _columns = { |
628 | 42 | 'description': fields.char('Description', size=64, translate=True), | 45 | 'sequence': fields.integer( |
629 | 43 | 'name': fields.char('Dimension Type Name', size=64, required=True), | 46 | 'Sequence', |
630 | 44 | 'sequence': fields.integer('Sequence', help=("The product 'variants' code will " | 47 | help=("The product 'variants' code will " |
631 | 45 | "use this to order the dimension values")), | 48 | "use this to order the dimension values")), |
632 | 46 | 'option_ids': fields.one2many('product.variant.dimension.option', 'dimension_id', | 49 | 'mandatory_dimension': fields.boolean( |
633 | 47 | 'Dimension Options'), | 50 | 'Mandatory Dimension', |
634 | 48 | 'product_tmpl_id': fields.many2many('product.template', 'product_template_dimension_rel', | 51 | help=("If false, variant products will be created " |
635 | 49 | 'dimension_id', 'template_id', 'Product Template'), | 52 | "with and without this dimension")), |
636 | 50 | 'allow_custom_value': fields.boolean('Allow Custom Value', | 53 | 'is_dimension': fields.boolean('Is dimension', help='Help note'), |
623 | 51 | help=("If true, custom values can be entered " | ||
624 | 52 | "in the product configurator")), | ||
625 | 53 | 'mandatory_dimension': fields.boolean('Mandatory Dimension', | ||
626 | 54 | help=("If false, variant products will be created " | ||
627 | 55 | "with and without this dimension")), | ||
637 | 56 | } | 54 | } |
638 | 57 | 55 | ||
639 | 58 | _defaults = { | 56 | _defaults = { |
640 | 59 | 'mandatory_dimension': 1, | 57 | 'mandatory_dimension': 1, |
673 | 60 | } | 58 | 'attribute_type': 'select', |
674 | 61 | 59 | } | |
675 | 62 | _order = "sequence, name" | 60 | |
676 | 63 | 61 | _order = "sequence" | |
677 | 64 | def name_search(self, cr, uid, name='', args=None, operator='ilike', context=None, limit=None): | 62 | |
678 | 65 | if not context.get('product_tmpl_id', False): | 63 | |
679 | 66 | args = None | 64 | class DimensionValue(orm.Model): |
680 | 67 | return super(product_variant_dimension_type, | 65 | _name = "dimension.value" |
649 | 68 | self).name_search(cr, uid, '', args, 'ilike', None, None) | ||
650 | 69 | |||
651 | 70 | |||
652 | 71 | class product_variant_dimension_option(orm.Model): | ||
653 | 72 | _name = "product.variant.dimension.option" | ||
654 | 73 | _description = "Dimension Option" | ||
655 | 74 | |||
656 | 75 | def _get_dimension_values(self, cr, uid, ids, context=None): | ||
657 | 76 | dimvalue_obj = self.pool.get('product.variant.dimension.value') | ||
658 | 77 | return dimvalue_obj.search(cr, uid, [('dimension_id', 'in', ids)], context=context) | ||
659 | 78 | |||
660 | 79 | _columns = { | ||
661 | 80 | 'name': fields.char('Dimension Option Name', size=64, required=True), | ||
662 | 81 | 'code': fields.char('Code', size=64), | ||
663 | 82 | 'sequence': fields.integer('Sequence'), | ||
664 | 83 | 'dimension_id': fields.many2one('product.variant.dimension.type', | ||
665 | 84 | 'Dimension Type', ondelete='cascade'), | ||
666 | 85 | } | ||
667 | 86 | |||
668 | 87 | _order = "dimension_id, sequence, name" | ||
669 | 88 | |||
670 | 89 | |||
671 | 90 | class product_variant_dimension_value(orm.Model): | ||
672 | 91 | _name = "product.variant.dimension.value" | ||
681 | 92 | _description = "Dimension Value" | 66 | _description = "Dimension Value" |
682 | 93 | 67 | ||
683 | 94 | def unlink(self, cr, uid, ids, context=None): | 68 | def unlink(self, cr, uid, ids, context=None): |
684 | 69 | product_obj = self.pool['product.product'] | ||
685 | 95 | for value in self.browse(cr, uid, ids, context=context): | 70 | for value in self.browse(cr, uid, ids, context=context): |
688 | 96 | if value.product_ids: | 71 | product_ids = product_obj.search(cr, uid, [ |
689 | 97 | product_names = [product.name for product in value.product_ids] | 72 | ['product_tmpl_id', '=', value.product_tmpl_id.id], |
690 | 73 | [value.dimension_id.name, '=', value.option_id.name], | ||
691 | 74 | ], context=context) | ||
692 | 75 | if product_ids: | ||
693 | 76 | products = product_obj.browse(cr, uid, product_ids, | ||
694 | 77 | context=context) | ||
695 | 78 | product_names = [product.name for product in products] | ||
696 | 98 | product_list = '\n - ' + '\n - '.join(product_names) | 79 | product_list = '\n - ' + '\n - '.join(product_names) |
702 | 99 | raise osv.except_osv(_('Dimension value can not be removed'), | 80 | raise osv.except_osv( |
703 | 100 | _("The value %s is used by the products : %s \n " | 81 | _('Dimension value can not be removed'), |
704 | 101 | "Please remove these products before removing the value.") | 82 | _("The value %s is used by the products : %s \n " |
705 | 102 | % (value.option_id.name, product_list)) | 83 | "Please remove these products before removing " |
706 | 103 | return super(product_variant_dimension_value, self).unlink(cr, uid, ids, context) | 84 | "the value.") % (value.option_id.name, product_list)) |
707 | 85 | return super(DimensionValue, self).\ | ||
708 | 86 | unlink(cr, uid, ids, context) | ||
709 | 104 | 87 | ||
710 | 105 | def _get_values_from_types(self, cr, uid, ids, context=None): | 88 | def _get_values_from_types(self, cr, uid, ids, context=None): |
717 | 106 | dimvalue_obj = self.pool.get('product.variant.dimension.value') | 89 | dimvalue_obj = self.pool.get('dimension.value') |
718 | 107 | return dimvalue_obj.search(cr, uid, [('dimension_id', 'in', ids)], context=context) | 90 | return dimvalue_obj.search(cr, uid, [ |
719 | 108 | 91 | ('dimension_id', 'in', ids), | |
720 | 109 | def _get_values_from_options(self, cr, uid, ids, context=None): | 92 | ], context=context) |
715 | 110 | dimvalue_obj = self.pool.get('product.variant.dimension.value') | ||
716 | 111 | return dimvalue_obj.search(cr, uid, [('option_id', 'in', ids)], context=context) | ||
721 | 112 | 93 | ||
722 | 113 | _columns = { | 94 | _columns = { |
727 | 114 | 'option_id': fields.many2one('product.variant.dimension.option', 'Option', required=True), | 95 | # TODO option_id add param in context |
728 | 115 | 'name': fields.related('option_id', 'name', type='char', | 96 | # to have a full name 'dimension + option' |
729 | 116 | relation='product.variant.dimension.option', | 97 | # exemple address on sale order |
730 | 117 | string="Dimension Value", readonly=True), | 98 | 'option_id': fields.many2one( |
731 | 99 | 'attribute.option', | ||
732 | 100 | 'Option', | ||
733 | 101 | required=True), | ||
734 | 102 | 'name': fields.related( | ||
735 | 103 | 'option_id', | ||
736 | 104 | 'name', | ||
737 | 105 | type='char', | ||
738 | 106 | string="Dimension Value", | ||
739 | 107 | readonly=True), | ||
740 | 118 | 'sequence': fields.integer('Sequence'), | 108 | 'sequence': fields.integer('Sequence'), |
768 | 119 | 'price_extra': fields.float('Sale Price Extra', | 109 | 'dimension_id': fields.many2one( |
769 | 120 | digits_compute=dp.get_precision('Sale Price')), | 110 | 'attribute.attribute', |
770 | 121 | 'price_margin': fields.float('Sale Price Margin', | 111 | 'Dimension', |
771 | 122 | digits_compute=dp.get_precision('Sale Price')), | 112 | required=True), |
772 | 123 | 'cost_price_extra': fields.float('Cost Price Extra', | 113 | 'product_tmpl_id': fields.many2one( |
773 | 124 | digits_compute=dp.get_precision('Purchase Price')), | 114 | 'product.template', |
774 | 125 | 'dimension_id': fields.related('option_id', 'dimension_id', type="many2one", | 115 | 'Product Template', |
775 | 126 | relation="product.variant.dimension.type", | 116 | ondelete='cascade'), |
776 | 127 | string="Dimension Type", | 117 | 'dimension_sequence': fields.related( |
777 | 128 | readonly=True, | 118 | 'dimension_id', |
778 | 129 | store={'product.variant.dimension.value': | 119 | 'sequence', |
779 | 130 | (lambda self, cr, uid, ids, c={}: | 120 | type='integer', |
780 | 131 | ids, ['option_id'], 10), | 121 | string="Related Dimension Sequence", |
781 | 132 | 'product.variant.dimension.option': | 122 | store={ |
782 | 133 | (_get_values_from_options, ['dimension_id'], 20)}), | 123 | 'attribute.attribute': ( |
783 | 134 | 'product_tmpl_id': fields.many2one('product.template', 'Product Template', | 124 | _get_values_from_types, |
784 | 135 | ondelete='cascade'), | 125 | ['sequence'], |
785 | 136 | 'dimension_sequence': fields.related('dimension_id', 'sequence', type='integer', | 126 | 10), |
786 | 137 | relation='product.variant.dimension.type', | 127 | 'dimension.value': ( |
787 | 138 | #used for ordering purposes in the "variants" | 128 | lambda self, cr, uid, ids, c={}: ids, |
788 | 139 | string="Related Dimension Sequence", | 129 | ['dimension_id'], |
789 | 140 | store={'product.variant.dimension.type': | 130 | 10), |
790 | 141 | (_get_values_from_types, ['sequence'], 10)}), | 131 | }), |
791 | 142 | 'product_ids': fields.many2many('product.product', 'product_product_dimension_rel', | 132 | 'active': fields.boolean( |
792 | 143 | 'dimension_id', 'product_id', 'Variant', readonly=True), | 133 | 'Active', |
793 | 144 | 'active': fields.boolean('Active', help=("If false, this value will not be " | 134 | help=("If false, this value will not be " |
794 | 145 | "used anymore to generate variants.")), | 135 | "used anymore to generate variants.")), |
795 | 146 | } | 136 | } |
796 | 147 | 137 | ||
797 | 148 | _defaults = { | 138 | _defaults = { |
798 | 149 | 'active': True, | 139 | 'active': True, |
799 | 150 | } | 140 | } |
800 | 151 | 141 | ||
810 | 152 | _sql_constraints = [('opt_dim_tmpl_uniq', | 142 | _sql_constraints = [ |
811 | 153 | 'UNIQUE(option_id, dimension_id, product_tmpl_id)', | 143 | ( |
812 | 154 | _("The combination option and dimension type " | 144 | 'opt_dim_tmpl_uniq', |
813 | 155 | "already exists for this product template !")), ] | 145 | 'UNIQUE(option_id, dimension_id, product_tmpl_id)', |
814 | 156 | 146 | _("The combination option and dimension type " | |
815 | 157 | _order = "dimension_sequence, dimension_id, sequence, option_id" | 147 | "already exists for this product template !") |
816 | 158 | 148 | ), | |
817 | 159 | 149 | ] | |
818 | 160 | class product_template(orm.Model): | 150 | |
819 | 151 | _order = "dimension_sequence, sequence, option_id" | ||
820 | 152 | |||
821 | 153 | def on_dimension_change(self, cr, uid, ids, dimension_id, context=None): | ||
822 | 154 | dim_obj = self.pool['attribute.attribute'] | ||
823 | 155 | dim = dim_obj.browse(cr, uid, dimension_id, context=context) | ||
824 | 156 | return { | ||
825 | 157 | 'domain': { | ||
826 | 158 | 'option_id': [ | ||
827 | 159 | ('id', 'in', [option.id for option in dim.option_ids]) | ||
828 | 160 | ] | ||
829 | 161 | }, | ||
830 | 162 | 'value': {'option_id': False}, | ||
831 | 163 | } | ||
832 | 164 | |||
833 | 165 | |||
834 | 166 | class StringTemplate(orm.Model): | ||
835 | 167 | _name = 'string.template' | ||
836 | 168 | |||
837 | 169 | def __get_type(self, cr, uid, context=None): | ||
838 | 170 | return self._get_type(cr, uid, context=context) | ||
839 | 171 | |||
840 | 172 | def _get_type(self, cr, uid, context=None): | ||
841 | 173 | return [ | ||
842 | 174 | ('product_code', 'Product Code'), | ||
843 | 175 | ('product_name', 'Product Name'), | ||
844 | 176 | ] | ||
845 | 177 | |||
846 | 178 | _columns = { | ||
847 | 179 | 'name': fields.char('name', required=True), | ||
848 | 180 | 'type': fields.selection(__get_type, 'Type', required=True), | ||
849 | 181 | 'code': fields.text('Code', required=True), | ||
850 | 182 | } | ||
851 | 183 | |||
852 | 184 | _defaults = { | ||
853 | 185 | 'code': """# Python code. Use result='YOUR_RESULT' to return your value. | ||
854 | 186 | # You can use the following variables : | ||
855 | 187 | # - self: ORM model of the record which is checked | ||
856 | 188 | # - o: browse_record of product template | ||
857 | 189 | # - pool: ORM model pool (i.e. self.pool) | ||
858 | 190 | # - datetime: Python datetime module | ||
859 | 191 | # - cr: database cursor | ||
860 | 192 | # - uid: current user id | ||
861 | 193 | # - context: current context | ||
862 | 194 | """ | ||
863 | 195 | } | ||
864 | 196 | |||
865 | 197 | def _eval_context(self, cr, uid, obj, context=None): | ||
866 | 198 | if context is None: | ||
867 | 199 | context = {} | ||
868 | 200 | user = self.pool.get('res.users').browse(cr, uid, uid, context=context) | ||
869 | 201 | return { | ||
870 | 202 | 'self': self.pool.get(obj._name), | ||
871 | 203 | 'o': obj, | ||
872 | 204 | 'pool': self.pool, | ||
873 | 205 | 'cr': cr, | ||
874 | 206 | 'uid': uid, | ||
875 | 207 | 'user': user, | ||
876 | 208 | 'datetime': datetime, | ||
877 | 209 | # copy context to prevent side-effects of eval | ||
878 | 210 | 'context': context.copy(), | ||
879 | 211 | } | ||
880 | 212 | |||
881 | 213 | def _build(self, cr, uid, template_id, obj, context=None): | ||
882 | 214 | if isinstance(template_id, (tuple, list)): | ||
883 | 215 | template_id = template_id[0] | ||
884 | 216 | template = self.browse(cr, uid, template_id, context=context) | ||
885 | 217 | expr = template.code | ||
886 | 218 | space = self._eval_context(cr, uid, obj, context=context) | ||
887 | 219 | try: | ||
888 | 220 | safe_eval(expr, | ||
889 | 221 | space, | ||
890 | 222 | mode='exec', | ||
891 | 223 | nocopy=True) # nocopy allows to return 'result' | ||
892 | 224 | except Exception, e: | ||
893 | 225 | if config['debug_mode']: raise | ||
894 | 226 | raise orm.except_orm( | ||
895 | 227 | _('Error'), | ||
896 | 228 | _('Error when evaluating the template:\n %s \n(%s)') | ||
897 | 229 | % (template.name, e)) | ||
898 | 230 | return space.get('result', False) | ||
899 | 231 | |||
900 | 232 | |||
901 | 233 | class ProductTemplate(orm.Model): | ||
902 | 161 | _inherit = "product.template" | 234 | _inherit = "product.template" |
903 | 162 | |||
904 | 163 | _order = "name" | 235 | _order = "name" |
905 | 164 | 236 | ||
906 | 237 | def _get_dimension_ids(self, cr, uid, ids, field_name, args, context=None): | ||
907 | 238 | result = {} | ||
908 | 239 | for product_tmpl in self.browse(cr, uid, ids, context=context): | ||
909 | 240 | attr_ids = [] | ||
910 | 241 | if product_tmpl.attribute_set_id: | ||
911 | 242 | for group in product_tmpl.attribute_set_id.attribute_group_ids: | ||
912 | 243 | for attr in group.attribute_ids: | ||
913 | 244 | attr_ids.append(attr.attribute_id.id) | ||
914 | 245 | result[product_tmpl.id] = attr_ids | ||
915 | 246 | return result | ||
916 | 247 | |||
917 | 165 | _columns = { | 248 | _columns = { |
941 | 166 | 'name': fields.char('Name', size=128, translate=True, select=True, required=False), | 249 | 'name': fields.char( |
942 | 167 | 'dimension_type_ids': fields.many2many('product.variant.dimension.type', | 250 | 'Name', size=128, |
943 | 168 | 'product_template_dimension_rel', | 251 | translate=True, |
944 | 169 | 'template_id', 'dimension_id', 'Dimension Types'), | 252 | select=True, |
945 | 170 | 'value_ids': fields.one2many('product.variant.dimension.value', | 253 | required=False), |
946 | 171 | 'product_tmpl_id', | 254 | 'value_ids': fields.one2many( |
947 | 172 | 'Dimension Values'), | 255 | 'dimension.value', |
948 | 173 | 'variant_ids': fields.one2many('product.product', 'product_tmpl_id', 'Variants'), | 256 | 'product_tmpl_id', |
949 | 174 | 'variant_model_name': fields.char('Variant Model Name', size=64, required=True, | 257 | 'Dimension Values'), |
950 | 175 | help=('[_o.dimension_id.name_] will be replaced with the' | 258 | 'dimension_ids': fields.function( |
951 | 176 | ' name of the dimension and [_o.option_id.code_] ' | 259 | _get_dimension_ids, |
952 | 177 | 'by the code of the option. Example of Variant ' | 260 | string='Dimension', |
953 | 178 | 'Model Name : "[_o.dimension_id.name_] - ' | 261 | type='many2many', |
954 | 179 | '[_o.option_id.code_]"')), | 262 | relation='attribute.attribute'), |
955 | 180 | 'variant_model_name_separator': fields.char('Variant Model Name Separator', size=64, | 263 | 'variant_ids': fields.one2many( |
956 | 181 | help=('Add a separator between the elements ' | 264 | 'product.product', |
957 | 182 | 'of the variant name')), | 265 | 'product_tmpl_id', |
958 | 183 | 'code_generator': fields.char('Code Generator', size=256, | 266 | 'Variants'), |
959 | 184 | help=('enter the model for the product code, all parameter' | 267 | 'template_name_id': fields.many2one( |
960 | 185 | ' between [_o.my_field_] will be replace by the ' | 268 | 'string.template', |
961 | 186 | 'product field. Example product_code model : ' | 269 | 'Template Name', |
962 | 187 | 'prefix_[_o.variants_]_suffixe ==> result : ' | 270 | required=True, |
963 | 188 | 'prefix_2S2T_suffix')), | 271 | domain=[('type', '=', 'product_name')], |
964 | 272 | ondelete='restrict'), | ||
965 | 273 | 'template_code_id': fields.many2one( | ||
966 | 274 | 'string.template', | ||
967 | 275 | 'Template Code', | ||
968 | 276 | required=True, | ||
969 | 277 | domain=[('type', '=', 'product_code')], | ||
970 | 278 | ondelete='restrict'), | ||
971 | 279 | 'base_default_code': fields.char( | ||
972 | 280 | 'Base Default Code', | ||
973 | 281 | size=256, | ||
974 | 282 | help=('Base Default Code of the template ' | ||
975 | 283 | 'used for generating the product code')), | ||
976 | 189 | 'is_multi_variants': fields.boolean('Is Multi Variants'), | 284 | 'is_multi_variants': fields.boolean('Is Multi Variants'), |
982 | 190 | 'variant_track_production': fields.boolean('Track Production Lots on variants ?'), | 285 | 'variant_track_production': fields.boolean( |
983 | 191 | 'variant_track_incoming': fields.boolean('Track Incoming Lots on variants ?'), | 286 | 'Track Production Lots on variants ?'), |
984 | 192 | 'variant_track_outgoing': fields.boolean('Track Outgoing Lots on variants ?'), | 287 | 'variant_track_incoming': fields.boolean( |
985 | 193 | 'do_not_update_variant': fields.boolean("Don't Update Variant"), | 288 | 'Track Incoming Lots on variants ?'), |
986 | 194 | 'do_not_generate_new_variant': fields.boolean("Don't Generate New Variant"), | 289 | 'variant_track_outgoing': fields.boolean( |
987 | 290 | 'Track Outgoing Lots on variants ?'), | ||
988 | 291 | 'do_not_update_variant': fields.boolean( | ||
989 | 292 | "Don't Update Variant"), | ||
990 | 293 | 'do_not_generate_new_variant': fields.boolean( | ||
991 | 294 | "Don't Generate New Variant"), | ||
992 | 195 | } | 295 | } |
993 | 196 | 296 | ||
994 | 297 | def _get_default_template_name(self, cr, uid, context=None): | ||
995 | 298 | tmpl_id = self.pool['string.template'].search(cr, uid, [ | ||
996 | 299 | ('type', '=', 'product_name'), | ||
997 | 300 | ], context=context) | ||
998 | 301 | return tmpl_id and tmpl_id[0] or False | ||
999 | 302 | |||
1000 | 303 | def _get_default_template_code(self, cr, uid, context=None): | ||
1001 | 304 | tmpl_id = self.pool['string.template'].search(cr, uid, [ | ||
1002 | 305 | ('type', '=', 'product_code'), | ||
1003 | 306 | ], context=context) | ||
1004 | 307 | return tmpl_id and tmpl_id[0] or False | ||
1005 | 308 | |||
1006 | 197 | _defaults = { | 309 | _defaults = { |
1007 | 198 | 'variant_model_name': '[_o.dimension_id.name_] - [_o.option_id.name_]', | ||
1008 | 199 | 'variant_model_name_separator': ' - ', | ||
1009 | 200 | 'is_multi_variants': False, | 310 | 'is_multi_variants': False, |
1012 | 201 | 'code_generator': ("[_'-'.join([x.option_id.name for x in o.dimension_value_ids] " | 311 | 'template_name_id': _get_default_template_name, |
1013 | 202 | "or ['CONF'])_]"), | 312 | 'template_code_id': _get_default_template_code, |
1014 | 203 | } | 313 | } |
1015 | 204 | 314 | ||
1016 | 205 | def unlink(self, cr, uid, ids, context=None): | 315 | def unlink(self, cr, uid, ids, context=None): |
1017 | 206 | if context and context.get('unlink_from_product_product', False): | 316 | if context and context.get('unlink_from_product_product', False): |
1018 | 207 | for template in self.browse(cr, uid, ids, context): | 317 | for template in self.browse(cr, uid, ids, context): |
1019 | 208 | if not template.is_multi_variants: | 318 | if not template.is_multi_variants: |
1021 | 209 | super(product_template, self).unlink(cr, uid, [template.id], context) | 319 | super(ProductTemplate, self).\ |
1022 | 320 | unlink(cr, uid, [template.id], context) | ||
1023 | 210 | else: | 321 | else: |
1024 | 211 | for template in self.browse(cr, uid, ids, context): | 322 | for template in self.browse(cr, uid, ids, context): |
1025 | 212 | if template.variant_ids == []: | 323 | if template.variant_ids == []: |
1027 | 213 | super(product_template, self).unlink(cr, uid, [template.id], context) | 324 | super(ProductTemplate, self).\ |
1028 | 325 | unlink(cr, uid, [template.id], context) | ||
1029 | 214 | else: | 326 | else: |
1052 | 215 | raise osv.except_osv(_("Cannot delete template"), | 327 | raise osv.except_osv( |
1053 | 216 | _("This template has existing corresponding products...")) | 328 | _("Cannot delete template"), |
1054 | 217 | return True | 329 | _("This template has existing corresponding " |
1055 | 218 | 330 | "products...")) | |
1034 | 219 | def add_all_option(self, cr, uid, ids, context=None): | ||
1035 | 220 | #Reactive all unactive values | ||
1036 | 221 | value_obj = self.pool.get('product.variant.dimension.value') | ||
1037 | 222 | for template in self.browse(cr, uid, ids, context=context): | ||
1038 | 223 | values_ids = value_obj.search(cr, uid, [['product_tmpl_id', '=', template.id], | ||
1039 | 224 | '|', ['active', '=', False], | ||
1040 | 225 | ['active', '=', True]], context=context) | ||
1041 | 226 | value_obj.write(cr, uid, values_ids, | ||
1042 | 227 | {'active': True}, | ||
1043 | 228 | context=context) | ||
1044 | 229 | values = value_obj.browse(cr, uid, values_ids, context=context) | ||
1045 | 230 | existing_option_ids = [value.option_id.id for value in values] | ||
1046 | 231 | vals = {'value_ids': []} | ||
1047 | 232 | for dim in template.dimension_type_ids: | ||
1048 | 233 | for option in dim.option_ids: | ||
1049 | 234 | if not option.id in existing_option_ids: | ||
1050 | 235 | vals['value_ids'] += [[0, 0, {'option_id': option.id}]] | ||
1051 | 236 | self.write(cr, uid, [template.id], vals, context=context) | ||
1056 | 237 | return True | 331 | return True |
1057 | 238 | 332 | ||
1058 | 239 | def get_products_from_product_template(self, cr, uid, ids, context=None): | 333 | def get_products_from_product_template(self, cr, uid, ids, context=None): |
1059 | @@ -245,12 +339,14 @@ | |||
1060 | 245 | default = {} | 339 | default = {} |
1061 | 246 | default = default.copy() | 340 | default = default.copy() |
1062 | 247 | default.update({'variant_ids': False, }) | 341 | default.update({'variant_ids': False, }) |
1064 | 248 | new_id = super(product_template, self).copy(cr, uid, id, default, context) | 342 | new_id = super(ProductTemplate, self).\ |
1065 | 343 | copy(cr, uid, id, default, context=context) | ||
1066 | 249 | 344 | ||
1068 | 250 | val_obj = self.pool.get('product.variant.dimension.value') | 345 | val_obj = self.pool.get('dimension.value') |
1069 | 251 | template = self.read(cr, uid, new_id, ['value_ids'], context=context) | 346 | template = self.read(cr, uid, new_id, ['value_ids'], context=context) |
1070 | 252 | # Making sure the values we duplicated are no longer linked via the | 347 | # Making sure the values we duplicated are no longer linked via the |
1072 | 253 | # m2m 'product_ids' with the product.product variants from the original template | 348 | # m2m 'product_ids' with the product.product variants |
1073 | 349 | # from the original template | ||
1074 | 254 | val_obj.write(cr, uid, template['value_ids'], { | 350 | val_obj.write(cr, uid, template['value_ids'], { |
1075 | 255 | 'product_ids': [(6, 0, [])], | 351 | 'product_ids': [(6, 0, [])], |
1076 | 256 | }, context=context) | 352 | }, context=context) |
1077 | @@ -260,384 +356,227 @@ | |||
1078 | 260 | def copy_translations(self, cr, uid, old_id, new_id, context=None): | 356 | def copy_translations(self, cr, uid, old_id, new_id, context=None): |
1079 | 261 | if context is None: | 357 | if context is None: |
1080 | 262 | context = {} | 358 | context = {} |
1082 | 263 | # avoid recursion through already copied records in case of circular relationship | 359 | # avoid recursion through already copied records in case |
1083 | 360 | # of circular relationship | ||
1084 | 264 | seen_map = context.setdefault('__copy_translations_seen', {}) | 361 | seen_map = context.setdefault('__copy_translations_seen', {}) |
1085 | 265 | if old_id in seen_map.setdefault(self._name, []): | 362 | if old_id in seen_map.setdefault(self._name, []): |
1086 | 266 | return | 363 | return |
1087 | 267 | seen_map[self._name].append(old_id) | 364 | seen_map[self._name].append(old_id) |
1090 | 268 | return super(product_template, self).copy_translations(cr, uid, old_id, new_id, | 365 | return super(ProductTemplate, self).\ |
1091 | 269 | context=context) | 366 | copy_translations(cr, uid, old_id, new_id, context=context) |
1092 | 270 | 367 | ||
1094 | 271 | def _create_variant_list(self, cr, ids, uid, vals, context=None): | 368 | def _create_variant_list(self, cr, uid, vals, context=None): |
1095 | 272 | 369 | ||
1096 | 273 | def cartesian_product(args): | 370 | def cartesian_product(args): |
1097 | 274 | if len(args) == 1: | 371 | if len(args) == 1: |
1098 | 275 | return [x and [x] or [] for x in args[0]] | 372 | return [x and [x] or [] for x in args[0]] |
1100 | 276 | return [(i and [i] or []) + j for j in cartesian_product(args[1:]) for i in args[0]] | 373 | return [(i and [i] or []) + j for j in cartesian_product(args[1:]) |
1101 | 374 | for i in args[0]] | ||
1102 | 277 | 375 | ||
1103 | 278 | return cartesian_product(vals) | 376 | return cartesian_product(vals) |
1104 | 279 | 377 | ||
1105 | 378 | def _get_combinaison(self, cr, uid, product_temp, context=None): | ||
1106 | 379 | res = defaultdict(list) | ||
1107 | 380 | |||
1108 | 381 | for value in product_temp.value_ids: | ||
1109 | 382 | res[value.dimension_id].append(value.option_id.id) | ||
1110 | 383 | |||
1111 | 384 | temp_val_list = [] | ||
1112 | 385 | for dim in res: | ||
1113 | 386 | temp_val_list += [ | ||
1114 | 387 | res[dim] | ||
1115 | 388 | + (not dim.mandatory_dimension and [None] or []) | ||
1116 | 389 | ] | ||
1117 | 390 | |||
1118 | 391 | # example temp_val_list is equal to [['red', 'blue', 'yellow'], | ||
1119 | 392 | # ['L', 'XL', 'M']] | ||
1120 | 393 | # In reallity it's not a string value but the id of the value | ||
1121 | 394 | |||
1122 | 395 | if not temp_val_list: | ||
1123 | 396 | return [] | ||
1124 | 397 | |||
1125 | 398 | combinaisons = self._create_variant_list( | ||
1126 | 399 | cr, uid, temp_val_list, context) | ||
1127 | 400 | return combinaisons | ||
1128 | 401 | |||
1129 | 402 | def _get_combinaisons_to_create(self, cr, uid, product_temp, | ||
1130 | 403 | existing_product_ids, context=None): | ||
1131 | 404 | variants_obj = self.pool['product.product'] | ||
1132 | 405 | |||
1133 | 406 | fields = set([dimension_value.dimension_id.name | ||
1134 | 407 | for dimension_value in product_temp.value_ids]) | ||
1135 | 408 | |||
1136 | 409 | combinaisons = self._get_combinaison( | ||
1137 | 410 | cr, uid, product_temp, context=context) | ||
1138 | 411 | |||
1139 | 412 | for combinaison in combinaisons: | ||
1140 | 413 | combinaison.sort() | ||
1141 | 414 | |||
1142 | 415 | existing_products = variants_obj.read( | ||
1143 | 416 | cr, uid, existing_product_ids, fields, context=context) | ||
1144 | 417 | |||
1145 | 418 | existing_combinaisons = [] | ||
1146 | 419 | for existing_product in existing_products: | ||
1147 | 420 | existing_combinaison = [] | ||
1148 | 421 | for field in fields: | ||
1149 | 422 | if existing_product[field]: | ||
1150 | 423 | existing_combinaison.append(existing_product[field][0]) | ||
1151 | 424 | else: | ||
1152 | 425 | existing_combinaison.append(None) | ||
1153 | 426 | existing_combinaison.sort() | ||
1154 | 427 | existing_combinaisons.append(existing_combinaison) | ||
1155 | 428 | |||
1156 | 429 | combinaisons_to_create = [x for x in combinaisons | ||
1157 | 430 | if not x in existing_combinaisons] | ||
1158 | 431 | |||
1159 | 432 | _logger.debug("variant existing : %s, variant to create : %s", | ||
1160 | 433 | len(existing_combinaisons), | ||
1161 | 434 | len(combinaisons_to_create)) | ||
1162 | 435 | return combinaisons_to_create | ||
1163 | 436 | |||
1164 | 437 | def _prepare_variant_vals(self, cr, uid, product_temp, combinaison, | ||
1165 | 438 | context=None): | ||
1166 | 439 | option_obj = self.pool['attribute.option'] | ||
1167 | 440 | vals = { | ||
1168 | 441 | 'name': product_temp.name, | ||
1169 | 442 | 'track_production': product_temp.variant_track_production, | ||
1170 | 443 | 'track_incoming': product_temp.variant_track_incoming, | ||
1171 | 444 | 'track_outgoing': product_temp.variant_track_outgoing, | ||
1172 | 445 | 'product_tmpl_id': product_temp.id, | ||
1173 | 446 | } | ||
1174 | 447 | option_ids = [option_id for option_id in combinaison if option_id] | ||
1175 | 448 | for option in option_obj.browse(cr, uid, option_ids, context=context): | ||
1176 | 449 | vals[option.attribute_id.name] = option.id | ||
1177 | 450 | return vals | ||
1178 | 451 | |||
1179 | 452 | def _create_variant(self, cr, uid, product_temp, existing_product_ids, | ||
1180 | 453 | context=None): | ||
1181 | 454 | variants_obj = self.pool['product.product'] | ||
1182 | 455 | created_product_ids = [] | ||
1183 | 456 | combinaisons_to_create = self.\ | ||
1184 | 457 | _get_combinaisons_to_create( | ||
1185 | 458 | cr, uid, product_temp, existing_product_ids, | ||
1186 | 459 | context=context) | ||
1187 | 460 | |||
1188 | 461 | count = 0 | ||
1189 | 462 | for combinaison in combinaisons_to_create: | ||
1190 | 463 | count += 1 | ||
1191 | 464 | vals = self._prepare_variant_vals( | ||
1192 | 465 | cr, uid, product_temp, combinaison, | ||
1193 | 466 | context=context) | ||
1194 | 467 | |||
1195 | 468 | cr.execute("SAVEPOINT pre_variant_save") | ||
1196 | 469 | try: | ||
1197 | 470 | product_id = variants_obj.create(cr, uid, vals, { | ||
1198 | 471 | 'generate_from_template': True, | ||
1199 | 472 | }) | ||
1200 | 473 | created_product_ids.append(product_id) | ||
1201 | 474 | if count % 50 == 0: | ||
1202 | 475 | _logger.debug("product created : %s", count) | ||
1203 | 476 | except Exception, e: | ||
1204 | 477 | if config['debug_mode']: | ||
1205 | 478 | raise | ||
1206 | 479 | _logger.error("Error creating product variant: %s", | ||
1207 | 480 | e, exc_info=True) | ||
1208 | 481 | _logger.debug("Values used to attempt creation of " | ||
1209 | 482 | "product variant: %s", vals) | ||
1210 | 483 | cr.execute("ROLLBACK TO SAVEPOINT pre_variant_save") | ||
1211 | 484 | cr.execute("RELEASE SAVEPOINT pre_variant_save") | ||
1212 | 485 | |||
1213 | 486 | _logger.debug("product created : %s", len(created_product_ids)) | ||
1214 | 487 | return created_product_ids | ||
1215 | 488 | |||
1216 | 489 | def _generate_variant_for_template(self, cr, uid, product_temp, | ||
1217 | 490 | context=None): | ||
1218 | 491 | variants_obj = self.pool['product.product'] | ||
1219 | 492 | created_product_ids = [] | ||
1220 | 493 | |||
1221 | 494 | existing_product_ids = variants_obj.search(cr, uid, [ | ||
1222 | 495 | ('product_tmpl_id', '=', product_temp.id) | ||
1223 | 496 | ], context=context) | ||
1224 | 497 | |||
1225 | 498 | if not product_temp.do_not_generate_new_variant: | ||
1226 | 499 | created_product_ids = self._create_variant( | ||
1227 | 500 | cr, uid, product_temp, existing_product_ids, | ||
1228 | 501 | context=context) | ||
1229 | 502 | |||
1230 | 503 | product_ids = existing_product_ids + created_product_ids | ||
1231 | 504 | |||
1232 | 505 | _logger.debug("Starting to generate/update variant names...") | ||
1233 | 506 | variants_obj.update_variant(cr, uid, product_ids, context=context) | ||
1234 | 507 | return True | ||
1235 | 508 | |||
1236 | 280 | def button_generate_variants(self, cr, uid, ids, context=None): | 509 | def button_generate_variants(self, cr, uid, ids, context=None): |
1320 | 281 | variants_obj = self.pool.get('product.product') | 510 | for product_temp in self.browse(cr, uid, ids, context=context): |
1321 | 282 | 511 | self._generate_variant_for_template( | |
1322 | 283 | for product_temp in self.browse(cr, uid, ids, context): | 512 | cr, uid, product_temp, context=context) |
1240 | 284 | res = {} | ||
1241 | 285 | temp_val_list = [] | ||
1242 | 286 | for value in product_temp.value_ids: | ||
1243 | 287 | if res.get(value.dimension_id, False): | ||
1244 | 288 | res[value.dimension_id] += [value.id] | ||
1245 | 289 | else: | ||
1246 | 290 | res[value.dimension_id] = [value.id] | ||
1247 | 291 | for dim in res: | ||
1248 | 292 | temp_val_list += [res[dim] + (not dim.mandatory_dimension and [None] or [])] | ||
1249 | 293 | |||
1250 | 294 | existing_product_ids = variants_obj.search(cr, uid, | ||
1251 | 295 | [('product_tmpl_id', '=', product_temp.id)]) | ||
1252 | 296 | created_product_ids = [] | ||
1253 | 297 | if temp_val_list and not product_temp.do_not_generate_new_variant: | ||
1254 | 298 | list_of_variants = self._create_variant_list(cr, uid, ids, temp_val_list, context) | ||
1255 | 299 | existing_product_dim_value = variants_obj.read(cr, uid, existing_product_ids, | ||
1256 | 300 | ['dimension_value_ids']) | ||
1257 | 301 | list_of_variants_existing = [x['dimension_value_ids'] | ||
1258 | 302 | for x in existing_product_dim_value] | ||
1259 | 303 | for x in list_of_variants_existing: | ||
1260 | 304 | x.sort() | ||
1261 | 305 | for x in list_of_variants: | ||
1262 | 306 | x.sort() | ||
1263 | 307 | list_of_variants_to_create = [x for x in list_of_variants | ||
1264 | 308 | if not x in list_of_variants_existing] | ||
1265 | 309 | |||
1266 | 310 | _logger.debug("variant existing : %s, variant to create : %s", | ||
1267 | 311 | len(list_of_variants_existing), | ||
1268 | 312 | len(list_of_variants_to_create)) | ||
1269 | 313 | count = 0 | ||
1270 | 314 | for variant in list_of_variants_to_create: | ||
1271 | 315 | count += 1 | ||
1272 | 316 | |||
1273 | 317 | vals = { | ||
1274 | 318 | 'name': product_temp.name, | ||
1275 | 319 | 'track_production': product_temp.variant_track_production, | ||
1276 | 320 | 'track_incoming': product_temp.variant_track_incoming, | ||
1277 | 321 | 'track_outgoing': product_temp.variant_track_outgoing, | ||
1278 | 322 | 'product_tmpl_id': product_temp.id, | ||
1279 | 323 | 'dimension_value_ids': [(6, 0, variant)], | ||
1280 | 324 | } | ||
1281 | 325 | |||
1282 | 326 | cr.execute("SAVEPOINT pre_variant_save") | ||
1283 | 327 | try: | ||
1284 | 328 | product_id = variants_obj.create(cr, uid, vals, | ||
1285 | 329 | {'generate_from_template': True}) | ||
1286 | 330 | created_product_ids.append(product_id) | ||
1287 | 331 | if count % 50 == 0: | ||
1288 | 332 | _logger.debug("product created : %s", count) | ||
1289 | 333 | except Exception, e: | ||
1290 | 334 | _logger.error("Error creating product variant: %s", | ||
1291 | 335 | e, exc_info=True) | ||
1292 | 336 | _logger.debug("Values used to attempt creation of product variant: %s", | ||
1293 | 337 | vals) | ||
1294 | 338 | cr.execute("ROLLBACK TO SAVEPOINT pre_variant_save") | ||
1295 | 339 | cr.execute("RELEASE SAVEPOINT pre_variant_save") | ||
1296 | 340 | |||
1297 | 341 | _logger.debug("product created : %s", count) | ||
1298 | 342 | |||
1299 | 343 | if not product_temp.do_not_update_variant: | ||
1300 | 344 | product_ids = existing_product_ids + created_product_ids | ||
1301 | 345 | else: | ||
1302 | 346 | product_ids = created_product_ids | ||
1303 | 347 | |||
1304 | 348 | # FIRST, Generate/Update variant names ('variants' field) | ||
1305 | 349 | _logger.debug("Starting to generate/update variant names...") | ||
1306 | 350 | self.pool.get('product.product').build_variants_name(cr, uid, product_ids, | ||
1307 | 351 | context=context) | ||
1308 | 352 | _logger.debug("End of the generation/update of variant names.") | ||
1309 | 353 | # SECOND, Generate/Update product codes and properties (we may need variants name) | ||
1310 | 354 | _logger.debug("Starting to generate/update product codes and properties...") | ||
1311 | 355 | self.pool.get('product.product').build_product_code_and_properties(cr, uid, | ||
1312 | 356 | product_ids, | ||
1313 | 357 | context=context) | ||
1314 | 358 | _logger.debug("End of the generation/update of product codes and properties.") | ||
1315 | 359 | # THIRD, Generate/Update product names (we may need variants name for that) | ||
1316 | 360 | _logger.debug("Starting to generate/update product names...") | ||
1317 | 361 | self.pool.get('product.product').build_product_name(cr, uid, product_ids, | ||
1318 | 362 | context=context) | ||
1319 | 363 | _logger.debug("End of generation/update of product names.") | ||
1323 | 364 | return True | 513 | return True |
1324 | 365 | 514 | ||
1325 | 366 | 515 | ||
1327 | 367 | class product_product(orm.Model): | 516 | class ProductProduct(orm.Model): |
1328 | 368 | _inherit = "product.product" | 517 | _inherit = "product.product" |
1329 | 369 | 518 | ||
1330 | 370 | def init(self, cr): | 519 | def init(self, cr): |
1334 | 371 | #For the first installation if you already have product in your database, | 520 | #TODO do it only for the first installation |
1335 | 372 | # the name of the existing product will be empty, so we fill it | 521 | #For the first installation if you already have product in |
1336 | 373 | cr.execute("update product_product set name=name_template where name is null;") | 522 | # your database, the name of the existing product will be empty, |
1337 | 523 | # so we fill it | ||
1338 | 524 | cr.execute("UPDATE product_product SET name=name_template " | ||
1339 | 525 | "WHERE name is null;") | ||
1340 | 374 | return True | 526 | return True |
1341 | 375 | 527 | ||
1342 | 376 | def unlink(self, cr, uid, ids, context=None): | 528 | def unlink(self, cr, uid, ids, context=None): |
1343 | 377 | if not context: | 529 | if not context: |
1344 | 378 | context = {} | 530 | context = {} |
1345 | 379 | context['unlink_from_product_product'] = True | 531 | context['unlink_from_product_product'] = True |
1362 | 380 | return super(product_product, self).unlink(cr, uid, ids, context) | 532 | return super(ProductProduct, self).unlink(cr, uid, ids, context) |
1363 | 381 | 533 | ||
1364 | 382 | def build_product_name(self, cr, uid, ids, context=None): | 534 | def update_variant(self, cr, uid, ids, context=None): |
1365 | 383 | return self.build_product_field(cr, uid, ids, 'name', context=None) | 535 | lang_obj = self.pool.get('res.lang') |
1366 | 384 | 536 | lang_ids = lang_obj.search(cr, uid, [ | |
1367 | 385 | def build_product_field(self, cr, uid, ids, field, context=None): | 537 | ('translatable', '=', True), |
1368 | 386 | def get_description_sale(product): | 538 | ], context=context) |
1369 | 387 | return self.parse(cr, uid, product, | 539 | for lang in lang_obj.browse(cr, uid, lang_ids, context=context): |
1370 | 388 | product.product_tmpl_id.description_sale, | 540 | context['lang'] = lang.code |
1371 | 389 | context=context) | 541 | for product in self.browse(cr, uid, ids, context=context): |
1372 | 390 | 542 | self._update_variant(cr, uid, product, context=context) | |
1373 | 391 | def get_name(product): | 543 | return True |
1374 | 392 | return (product.product_tmpl_id.name or '') + ' ' + (product.variants or '') | 544 | |
1375 | 393 | 545 | def _update_variant(self, cr, uid, product, context=None): | |
1376 | 394 | if not context: | 546 | vals = self._prepare_update_vals(cr, uid, product, context=context) |
1377 | 395 | context = {} | 547 | vals = self._remove_not_updated(cr, uid, product, vals, context=context) |
1378 | 548 | if vals: | ||
1379 | 549 | product.write(vals) | ||
1380 | 550 | return True | ||
1381 | 551 | |||
1382 | 552 | def _prepare_update_vals(self, cr, uid, product, context=None): | ||
1383 | 396 | context['is_multi_variants'] = True | 553 | context['is_multi_variants'] = True |
1577 | 397 | obj_lang = self.pool.get('res.lang') | 554 | string_template_obj = self.pool['string.template'] |
1578 | 398 | lang_ids = obj_lang.search(cr, uid, [('translatable', '=', True)], context=context) | 555 | vals = { |
1579 | 399 | lang_code = [x['code'] | 556 | 'variants': string_template_obj._build( |
1580 | 400 | for x in obj_lang.read(cr, uid, lang_ids, ['code'], context=context)] | 557 | cr, uid, product.template_name_id.id, product), |
1581 | 401 | for code in lang_code: | 558 | 'default_code': string_template_obj._build( |
1582 | 402 | context['lang'] = code | 559 | cr, uid, product.template_code_id.id, product), |
1583 | 403 | for product in self.browse(cr, uid, ids, context=context): | 560 | } |
1584 | 404 | new_field_value = eval("get_" + field + "(product)") # TODO convert to safe_eval | 561 | vals['name'] = "%s %s" % ( |
1585 | 405 | cur_field_value = safe_eval("product." + field, {'product': product}) | 562 | product.product_tmpl_id.name or '', |
1586 | 406 | if new_field_value != cur_field_value: | 563 | vals['variants']) |
1587 | 407 | self.write(cr, uid, [product.id], {field: new_field_value}, context=context) | 564 | return vals |
1588 | 408 | return True | 565 | |
1589 | 409 | 566 | def _remove_not_updated(self, cr, uid, product, vals, context=None): | |
1590 | 410 | def parse(self, cr, uid, o, text, context=None): | 567 | vals_to_write = {} |
1591 | 411 | if not text: | 568 | for key in vals: |
1592 | 412 | return '' | 569 | if vals[key] != product[key]: |
1593 | 413 | vals = text.split('[_') | 570 | vals_to_write[key] = vals[key] |
1594 | 414 | description = '' | 571 | return vals_to_write |
1402 | 415 | for val in vals: | ||
1403 | 416 | if '_]' in val: | ||
1404 | 417 | sub_val = val.split('_]') | ||
1405 | 418 | try: | ||
1406 | 419 | description += (safe_eval(sub_val[0], {'o': o, 'context': context}) | ||
1407 | 420 | or '' | ||
1408 | 421 | ) + sub_val[1] | ||
1409 | 422 | except AttributeError: | ||
1410 | 423 | raise osv.except_osv(_('Bad expression'), | ||
1411 | 424 | _("One of your expressions contains " | ||
1412 | 425 | "a non existing attribute: %s" | ||
1413 | 426 | ) % sub_val[0]) | ||
1414 | 427 | else: | ||
1415 | 428 | description += val | ||
1416 | 429 | return description | ||
1417 | 430 | |||
1418 | 431 | def generate_product_code(self, cr, uid, product_obj, code_generator, context=None): | ||
1419 | 432 | '''I wrote this stupid function to be able to inherit it in a custom module !''' | ||
1420 | 433 | return self.parse(cr, uid, product_obj, code_generator, context=context) | ||
1421 | 434 | |||
1422 | 435 | def build_product_code_and_properties(self, cr, uid, ids, context=None): | ||
1423 | 436 | for product in self.browse(cr, uid, ids, context=context): | ||
1424 | 437 | new_default_code = self.generate_product_code(cr, uid, product, | ||
1425 | 438 | product.product_tmpl_id.code_generator, | ||
1426 | 439 | context=context) | ||
1427 | 440 | current_values = { | ||
1428 | 441 | 'default_code': product.default_code, | ||
1429 | 442 | #'track_production': product.track_production, | ||
1430 | 443 | #'track_outgoing': product.track_outgoing, | ||
1431 | 444 | #'track_incoming': product.track_incoming, | ||
1432 | 445 | } | ||
1433 | 446 | new_values = { | ||
1434 | 447 | 'default_code': new_default_code, | ||
1435 | 448 | #'track_production': product.product_tmpl_id.variant_track_production, | ||
1436 | 449 | #'track_outgoing': product.product_tmpl_id.variant_track_outgoing, | ||
1437 | 450 | #'track_incoming': product.product_tmpl_id.variant_track_incoming, | ||
1438 | 451 | } | ||
1439 | 452 | if new_values != current_values: | ||
1440 | 453 | self.write(cr, uid, [product.id], new_values, context=context) | ||
1441 | 454 | return True | ||
1442 | 455 | |||
1443 | 456 | def product_ids_variant_changed(self, cr, uid, ids, res, context=None): | ||
1444 | 457 | '''it's a hook for product_variant_multi advanced''' | ||
1445 | 458 | return True | ||
1446 | 459 | |||
1447 | 460 | def generate_variant_name(self, cr, uid, product_id, context=None): | ||
1448 | 461 | '''Do the generation of the variant name in a dedicated function, so that we can | ||
1449 | 462 | inherit this function to hack the code generation''' | ||
1450 | 463 | product = self.browse(cr, uid, product_id, context=context) | ||
1451 | 464 | model = product.variant_model_name | ||
1452 | 465 | r = map(lambda dim: [dim.dimension_id.sequence, | ||
1453 | 466 | self.parse(cr, uid, dim, model, context=context)], | ||
1454 | 467 | product.dimension_value_ids) | ||
1455 | 468 | r.sort() | ||
1456 | 469 | r = [x[1] for x in r] | ||
1457 | 470 | new_variant_name = (product.variant_model_name_separator or '').join(r) | ||
1458 | 471 | return new_variant_name | ||
1459 | 472 | |||
1460 | 473 | def build_variants_name(self, cr, uid, ids, context=None): | ||
1461 | 474 | for product in self.browse(cr, uid, ids, context=context): | ||
1462 | 475 | new_variant_name = self.generate_variant_name(cr, uid, product.id, context=context) | ||
1463 | 476 | if new_variant_name != product.variants: | ||
1464 | 477 | self.write(cr, uid, [product.id], {'variants': new_variant_name}, context=context) | ||
1465 | 478 | return True | ||
1466 | 479 | |||
1467 | 480 | def _check_dimension_values(self, cr, uid, ids): | ||
1468 | 481 | # TODO: check that all dimension_types of the product_template | ||
1469 | 482 | # have a corresponding dimension_value ?? | ||
1470 | 483 | for product in self.browse(cr, uid, ids, {}): | ||
1471 | 484 | buffer = [] | ||
1472 | 485 | for value in product.dimension_value_ids: | ||
1473 | 486 | buffer.append(value.dimension_id) | ||
1474 | 487 | unique_set = set(buffer) | ||
1475 | 488 | if len(unique_set) != len(buffer): | ||
1476 | 489 | raise orm.except_orm(_('Constraint error :'), | ||
1477 | 490 | _("On product '%s', there are several dimension values " | ||
1478 | 491 | "for the same dimension type.") % product.name) | ||
1479 | 492 | return True | ||
1480 | 493 | |||
1481 | 494 | def compute_product_dimension_extra_price(self, cr, uid, product_id, | ||
1482 | 495 | product_price_extra=False, dim_price_margin=False, | ||
1483 | 496 | dim_price_extra=False, context=None): | ||
1484 | 497 | if context is None: | ||
1485 | 498 | context = {} | ||
1486 | 499 | dimension_extra = 0.0 | ||
1487 | 500 | product = self.browse(cr, uid, product_id, context=context) | ||
1488 | 501 | for dim in product.dimension_value_ids: | ||
1489 | 502 | if product_price_extra and dim_price_margin and dim_price_extra: | ||
1490 | 503 | dimension_extra += (safe_eval('product.' + product_price_extra, | ||
1491 | 504 | {'product': product}) | ||
1492 | 505 | * safe_eval('dim.' + dim_price_margin, | ||
1493 | 506 | {'dim': dim}) | ||
1494 | 507 | + safe_eval('dim.' + dim_price_extra, | ||
1495 | 508 | {'dim': dim})) | ||
1496 | 509 | elif not product_price_extra and not dim_price_margin and dim_price_extra: | ||
1497 | 510 | dimension_extra += safe_eval('dim.' + dim_price_extra, {'dim': dim}) | ||
1498 | 511 | elif product_price_extra and dim_price_margin and not dim_price_extra: | ||
1499 | 512 | dimension_extra += (safe_eval('product.' + product_price_extra, | ||
1500 | 513 | {'product': product}) | ||
1501 | 514 | * safe_eval('dim.' + dim_price_margin, | ||
1502 | 515 | {'dim': dim})) | ||
1503 | 516 | elif product_price_extra and not dim_price_margin and dim_price_extra: | ||
1504 | 517 | dimension_extra += (safe_eval('product.' + product_price_extra, | ||
1505 | 518 | {'product': product}) | ||
1506 | 519 | + safe_eval('dim.' + dim_price_extra, {'dim': dim})) | ||
1507 | 520 | |||
1508 | 521 | if 'uom' in context: | ||
1509 | 522 | product_uom_obj = self.pool.get('product.uom') | ||
1510 | 523 | uom = product.uos_id or product.uom_id | ||
1511 | 524 | dimension_extra = product_uom_obj._compute_price(cr, uid, uom.id, | ||
1512 | 525 | dimension_extra, context['uom']) | ||
1513 | 526 | return dimension_extra | ||
1514 | 527 | |||
1515 | 528 | def compute_dimension_extra_price(self, cr, uid, ids, result, product_price_extra=False, | ||
1516 | 529 | dim_price_margin=False, dim_price_extra=False, context=None): | ||
1517 | 530 | if context is None: | ||
1518 | 531 | context = {} | ||
1519 | 532 | for product in self.browse(cr, uid, ids, context=context): | ||
1520 | 533 | dimension_extra = self.compute_product_dimension_extra_price( | ||
1521 | 534 | cr, uid, product.id, | ||
1522 | 535 | product_price_extra=product_price_extra, | ||
1523 | 536 | dim_price_margin=dim_price_margin, | ||
1524 | 537 | dim_price_extra=dim_price_extra, | ||
1525 | 538 | context=context) | ||
1526 | 539 | result[product.id] += dimension_extra | ||
1527 | 540 | return result | ||
1528 | 541 | |||
1529 | 542 | def price_get(self, cr, uid, ids, ptype='list_price', context=None): | ||
1530 | 543 | if context is None: | ||
1531 | 544 | context = {} | ||
1532 | 545 | result = super(product_product, self).price_get(cr, uid, ids, ptype, context=context) | ||
1533 | 546 | if ptype == 'list_price': | ||
1534 | 547 | #TODO check if the price_margin on the dimension is very usefull, | ||
1535 | 548 | # maybe we will remove it | ||
1536 | 549 | result = self.compute_dimension_extra_price( | ||
1537 | 550 | cr, uid, ids, result, | ||
1538 | 551 | product_price_extra='price_extra', | ||
1539 | 552 | dim_price_margin='price_margin', | ||
1540 | 553 | dim_price_extra='price_extra', | ||
1541 | 554 | context=context) | ||
1542 | 555 | elif ptype == 'standard_price': | ||
1543 | 556 | result = self.compute_dimension_extra_price( | ||
1544 | 557 | cr, uid, ids, result, | ||
1545 | 558 | product_price_extra='cost_price_extra', | ||
1546 | 559 | dim_price_extra='cost_price_extra', | ||
1547 | 560 | context=context) | ||
1548 | 561 | return result | ||
1549 | 562 | |||
1550 | 563 | def _product_lst_price(self, cr, uid, ids, name, arg, context=None): | ||
1551 | 564 | if context is None: | ||
1552 | 565 | context = {} | ||
1553 | 566 | result = super(product_product, self)._product_lst_price(cr, uid, ids, name, arg, | ||
1554 | 567 | context=context) | ||
1555 | 568 | result = self.compute_dimension_extra_price(cr, uid, ids, result, | ||
1556 | 569 | product_price_extra='price_extra', | ||
1557 | 570 | dim_price_margin='price_margin', | ||
1558 | 571 | dim_price_extra='price_extra', | ||
1559 | 572 | context=context) | ||
1560 | 573 | return result | ||
1561 | 574 | |||
1562 | 575 | def copy(self, cr, uid, id, default=None, context=None): | ||
1563 | 576 | if default is None: | ||
1564 | 577 | default = {} | ||
1565 | 578 | default = default.copy() | ||
1566 | 579 | default.update({'variant_ids': False}) | ||
1567 | 580 | return super(product_product, self).copy(cr, uid, id, default, context) | ||
1568 | 581 | |||
1569 | 582 | def _product_compute_weight_volume(self, cr, uid, ids, fields, arg, context=None): | ||
1570 | 583 | result = {} | ||
1571 | 584 | for product in self.browse(cr, uid, ids, context=context): | ||
1572 | 585 | result[product.id] = p = {} | ||
1573 | 586 | p['total_weight'] = product.weight + product.additional_weight | ||
1574 | 587 | p['total_weight_net'] = product.weight_net + product.additional_weight_net | ||
1575 | 588 | p['total_volume'] = product.volume + product.additional_volume | ||
1576 | 589 | return result | ||
1595 | 590 | 572 | ||
1596 | 591 | _columns = { | 573 | _columns = { |
1644 | 592 | 'name': fields.char('Name', size=128, translate=True, select=True), | 574 | 'name': fields.char( |
1645 | 593 | 'variants': fields.char('Variants', size=128), | 575 | 'Name', |
1646 | 594 | 'dimension_value_ids': fields.many2many( | 576 | size=128, |
1647 | 595 | 'product.variant.dimension.value', | 577 | translate=True, |
1648 | 596 | 'product_product_dimension_rel', | 578 | select=True), |
1649 | 597 | 'product_id', 'dimension_id', | 579 | 'variants': fields.char( |
1650 | 598 | 'Dimensions', | 580 | 'Variants', |
1651 | 599 | domain="[('product_tmpl_id','=',product_tmpl_id)]"), | 581 | size=128), |
1605 | 600 | 'cost_price_extra': fields.float('Purchase Extra Cost', | ||
1606 | 601 | digits_compute=dp.get_precision('Purchase Price')), | ||
1607 | 602 | 'lst_price': fields.function(_product_lst_price, | ||
1608 | 603 | method=True, | ||
1609 | 604 | type='float', | ||
1610 | 605 | string='List Price', | ||
1611 | 606 | digits_compute=dp.get_precision('Sale Price')), | ||
1612 | 607 | #the way the weight are implemented are not clean at all, | ||
1613 | 608 | #we should redesign the module product form the addons | ||
1614 | 609 | #in order to get something correclty. | ||
1615 | 610 | #indeed some field of the template have to be overwrited | ||
1616 | 611 | #like weight, name, weight_net, volume. | ||
1617 | 612 | #in order to have a consitent api we should use the same field for getting the weight, | ||
1618 | 613 | #now we have to use "weight" or "total_weight" | ||
1619 | 614 | #not clean at all with external syncronization | ||
1620 | 615 | 'total_weight': fields.function(_product_compute_weight_volume, | ||
1621 | 616 | method=True, | ||
1622 | 617 | type='float', | ||
1623 | 618 | string='Total Gross Weight', | ||
1624 | 619 | help="The gross weight in Kg.", | ||
1625 | 620 | multi='weight_volume'), | ||
1626 | 621 | 'total_weight_net': fields.function(_product_compute_weight_volume, | ||
1627 | 622 | method=True, | ||
1628 | 623 | type='float', | ||
1629 | 624 | string='Total Net Weight', | ||
1630 | 625 | help="The net weight in Kg.", | ||
1631 | 626 | multi='weight_volume'), | ||
1632 | 627 | 'total_volume': fields.function(_product_compute_weight_volume, | ||
1633 | 628 | method=True, | ||
1634 | 629 | type='float', | ||
1635 | 630 | string='Total Volume', | ||
1636 | 631 | help="The volume in m3.", | ||
1637 | 632 | multi='weight_volume'), | ||
1638 | 633 | 'additional_weight': fields.float('Additional Gross weight', | ||
1639 | 634 | help="The additional gross weight in Kg."), | ||
1640 | 635 | 'additional_weight_net': fields.float('Additional Net weight', | ||
1641 | 636 | help="The additional net weight in Kg."), | ||
1642 | 637 | 'additional_volume': fields.float('Additional Volume', | ||
1643 | 638 | help="The additional volume in Kg."), | ||
1652 | 639 | } | 582 | } |
1653 | 640 | |||
1654 | 641 | _constraints = [ | ||
1655 | 642 | (_check_dimension_values, 'Error msg in raise', ['dimension_value_ids']), | ||
1656 | 643 | ] | ||
1657 | 644 | 583 | ||
1658 | === modified file 'product_variant_generator/product_view.xml' | |||
1659 | --- product_variant_multi/product_view.xml 2013-04-22 21:00:07 +0000 | |||
1660 | +++ product_variant_generator/product_view.xml 2014-06-24 09:37:35 +0000 | |||
1661 | @@ -3,224 +3,108 @@ | |||
1662 | 3 | <data> | 3 | <data> |
1663 | 4 | 4 | ||
1664 | 5 | <!-- | 5 | <!-- |
1666 | 6 | "Product variant multi" module for OpenERP | 6 | "Product variant generator" module for OpenERP |
1667 | 7 | The licence is in the file __openerp__.py | 7 | The licence is in the file __openerp__.py |
1668 | 8 | @author Alexis de Lattre <alexis.delattre@akretion.com> | 8 | @author Alexis de Lattre <alexis.delattre@akretion.com> |
1669 | 9 | @author Sebastien Beau <sebastien.beau@akretion.com> | 9 | @author Sebastien Beau <sebastien.beau@akretion.com> |
1670 | 10 | @author Chafique Delli <chafique.delli@akretion.com> | ||
1671 | 10 | --> | 11 | --> |
1672 | 11 | 12 | ||
1673 | 12 | |||
1674 | 13 | <menuitem name="Variant Dimensions" id="menu_variant_dimension" parent="product.prod_config_main" /> | ||
1675 | 14 | |||
1676 | 15 | |||
1677 | 16 | <!-- DIMENSION OPTION --> | ||
1678 | 17 | <record id="product_variant_multi_dimension_option_seach" model="ir.ui.view"> | ||
1679 | 18 | <field name="name">product.variant.multi.dimension.option.search</field> | ||
1680 | 19 | <field name="model">product.variant.dimension.option</field> | ||
1681 | 20 | <field name="arch" type="xml"> | ||
1682 | 21 | <search string="Dimension Options Search"> | ||
1683 | 22 | <field name="name"/> | ||
1684 | 23 | <field name="dimension_id"/> | ||
1685 | 24 | </search> | ||
1686 | 25 | </field> | ||
1687 | 26 | </record> | ||
1688 | 27 | |||
1689 | 28 | <record id="product_variant_multi_dimension_option_tree" model="ir.ui.view"> | ||
1690 | 29 | <field name="name">product.variant.multi.dimension.option.tree</field> | ||
1691 | 30 | <field name="model">product.variant.dimension.option</field> | ||
1692 | 31 | <field name="arch" type="xml"> | ||
1693 | 32 | <tree string="Dimension Options" editable="top"> | ||
1694 | 33 | <field name="dimension_id" invisible="not context.get('dimension_option_main_view', False)" /> | ||
1695 | 34 | <field name="name" /> | ||
1696 | 35 | <field name="sequence" /> | ||
1697 | 36 | <field name="code" /> | ||
1698 | 37 | </tree> | ||
1699 | 38 | </field> | ||
1700 | 39 | </record> | ||
1701 | 40 | |||
1702 | 41 | <record id="product_variant_multi_dimension_option_form" model="ir.ui.view"> | ||
1703 | 42 | <field name="name">product.variant.multi.dimension.option.form</field> | ||
1704 | 43 | <field name="model">product.variant.dimension.option</field> | ||
1705 | 44 | <field name="arch" type="xml"> | ||
1706 | 45 | <form string="Dimension Options"> | ||
1707 | 46 | <field name="dimension_id" invisible="not context.get('dimension_option_main_view', False)" /> | ||
1708 | 47 | <newline /> | ||
1709 | 48 | <field name="sequence" /> | ||
1710 | 49 | <field name="name" /> | ||
1711 | 50 | <field name="code" /> | ||
1712 | 51 | </form> | ||
1713 | 52 | </field> | ||
1714 | 53 | </record> | ||
1715 | 54 | |||
1716 | 55 | <record id="action_dimension_option" model="ir.actions.act_window"> | ||
1717 | 56 | <field name="name">Dimension Options</field> | ||
1718 | 57 | <field name="res_model">product.variant.dimension.option</field> | ||
1719 | 58 | <field name="view_type">form</field> | ||
1720 | 59 | <field name="view_mode">tree,form</field> | ||
1721 | 60 | <field name="context">{'dimension_option_main_view': True}</field> | ||
1722 | 61 | </record> | ||
1723 | 62 | |||
1724 | 63 | <menuitem id="menu_variant_dimension_option" parent="menu_variant_dimension" action="action_dimension_option" /> | ||
1725 | 64 | |||
1726 | 65 | |||
1727 | 66 | <!-- DIMENSION VALUES --> | 13 | <!-- DIMENSION VALUES --> |
1743 | 67 | <record id="product_variant_multi_dimension_value_search" model="ir.ui.view"> | 14 | <record id="dimension_value_tree" model="ir.ui.view"> |
1744 | 68 | <field name="name">product.variant.multi.dimension.value.search</field> | 15 | <field name="model">dimension.value</field> |
1730 | 69 | <field name="model">product.variant.dimension.value</field> | ||
1731 | 70 | <field name="arch" type="xml"> | ||
1732 | 71 | <search string="Dimension Values Search"> | ||
1733 | 72 | <field name="product_tmpl_id"/> | ||
1734 | 73 | <field name="option_id"/> | ||
1735 | 74 | </search> | ||
1736 | 75 | </field> | ||
1737 | 76 | </record> | ||
1738 | 77 | |||
1739 | 78 | |||
1740 | 79 | <record id="product_variant_multi_dimension_value_tree" model="ir.ui.view"> | ||
1741 | 80 | <field name="name">product.variant.multi.dimension.value.tree</field> | ||
1742 | 81 | <field name="model">product.variant.dimension.value</field> | ||
1745 | 82 | <field name="arch" type="xml"> | 16 | <field name="arch" type="xml"> |
1746 | 83 | <tree string="Dimension Values" editable="top"> | 17 | <tree string="Dimension Values" editable="top"> |
1748 | 84 | <field name="product_tmpl_id" invisible="not context.get('dimension_value_main_view', False)" /> | 18 | <field name="product_tmpl_id" |
1749 | 19 | invisible="not context.get('dimension_value_main_view', False)"/> | ||
1750 | 85 | <field name="active" /> | 20 | <field name="active" /> |
1751 | 86 | <field name="dimension_id" /> | ||
1752 | 87 | <field name="option_id" /> | 21 | <field name="option_id" /> |
1753 | 88 | <field name="sequence" /> | 22 | <field name="sequence" /> |
1754 | 89 | <field name="cost_price_extra" /> | ||
1755 | 90 | <field name="price_extra" /> | ||
1756 | 91 | </tree> | 23 | </tree> |
1757 | 92 | </field> | 24 | </field> |
1758 | 93 | </record> | 25 | </record> |
1759 | 94 | 26 | ||
1760 | 95 | <record id="product_variant_multi_dimension_value_form" model="ir.ui.view"> | 27 | <record id="product_variant_multi_dimension_value_form" model="ir.ui.view"> |
1763 | 96 | <field name="name">product.variant.multi.dimension.value.form</field> | 28 | <field name="model">dimension.value</field> |
1762 | 97 | <field name="model">product.variant.dimension.value</field> | ||
1764 | 98 | <field name="arch" type="xml"> | 29 | <field name="arch" type="xml"> |
1765 | 99 | <form string="Dimension Values"> | 30 | <form string="Dimension Values"> |
1767 | 100 | <field name="product_tmpl_id" invisible="not context.get('dimension_value_main_view', False)" /> | 31 | <field name="product_tmpl_id" |
1768 | 32 | invisible="not context.get('dimension_value_main_view', False)"/> | ||
1769 | 101 | <field name="active" /> | 33 | <field name="active" /> |
1770 | 102 | <field name="dimension_id" /> | ||
1771 | 103 | <newline /> | 34 | <newline /> |
1772 | 104 | <field name="option_id" /> | 35 | <field name="option_id" /> |
1773 | 105 | <field name="sequence" /> | 36 | <field name="sequence" /> |
1774 | 106 | <field name="cost_price_extra" /> | ||
1775 | 107 | <field name="price_extra" /> | ||
1776 | 108 | <field name="price_margin" /> | ||
1777 | 109 | </form> | 37 | </form> |
1778 | 110 | </field> | 38 | </field> |
1779 | 111 | </record> | 39 | </record> |
1780 | 112 | 40 | ||
1781 | 113 | <record id="action_dimension_value" model="ir.actions.act_window"> | 41 | <record id="action_dimension_value" model="ir.actions.act_window"> |
1782 | 114 | <field name="name">Dimension values</field> | 42 | <field name="name">Dimension values</field> |
1784 | 115 | <field name="res_model">product.variant.dimension.value</field> | 43 | <field name="res_model">dimension.value</field> |
1785 | 116 | <field name="view_type">form</field> | 44 | <field name="view_type">form</field> |
1786 | 117 | <field name="view_mode">tree,form</field> | 45 | <field name="view_mode">tree,form</field> |
1787 | 118 | <field name="context">{'dimension_value_main_view': True}</field> | 46 | <field name="context">{'dimension_value_main_view': True}</field> |
1788 | 119 | </record> | 47 | </record> |
1789 | 120 | 48 | ||
1848 | 121 | 49 | <record id="attribute_attribute_form_view" model="ir.ui.view"> | |
1849 | 122 | <!-- DIMENSION TYPE --> | 50 | <field name="model">attribute.attribute</field> |
1850 | 123 | <record id="product_variant_multi_dimension_type_search" model="ir.ui.view"> | 51 | <field name="inherit_id" ref="base_custom_attributes.attribute_attribute_form_view"/> |
1851 | 124 | <field name="name">product.variant.multi.dimension.type.search</field> | 52 | <field name="arch" type="xml"> |
1852 | 125 | <field name="model">product.variant.dimension.type</field> | 53 | <field name="translate" position="after"> |
1853 | 126 | <field name="arch" type="xml"> | 54 | <field name="is_dimension"/> |
1854 | 127 | <search string="Dimension Type Search"> | 55 | <field name="sequence" |
1855 | 128 | <field name="name"/> | 56 | attrs="{'invisible': [('is_dimension','=', False)]}"/> |
1856 | 129 | </search> | 57 | <field name="mandatory_dimension" |
1857 | 130 | </field> | 58 | attrs="{'invisible': [('is_dimension','=', False)]}"/> |
1858 | 131 | </record> | 59 | </field> |
1859 | 132 | 60 | </field> | |
1860 | 133 | <record id="product_variant_multi_dimension_type_tree" model="ir.ui.view"> | 61 | </record> |
1803 | 134 | <field name="name">product.variant.multi.dimension.type.tree</field> | ||
1804 | 135 | <field name="model">product.variant.dimension.type</field> | ||
1805 | 136 | <field name="arch" type="xml"> | ||
1806 | 137 | <tree string="Dimension Types"> | ||
1807 | 138 | <field name="name" /> | ||
1808 | 139 | <field name="description" /> | ||
1809 | 140 | </tree> | ||
1810 | 141 | </field> | ||
1811 | 142 | </record> | ||
1812 | 143 | |||
1813 | 144 | <record id="product_variant_multi_dimension_type_form" model="ir.ui.view"> | ||
1814 | 145 | <field name="name">product.variant.multi.dimension.type.form</field> | ||
1815 | 146 | <field name="model">product.variant.dimension.type</field> | ||
1816 | 147 | <field name="arch" type="xml"> | ||
1817 | 148 | <form string="Dimension Types" version="7.0"> | ||
1818 | 149 | <sheet> | ||
1819 | 150 | <div class="oe_title"> | ||
1820 | 151 | <label for="name" string="Dimension Type Name" class="oe_edit_only"/> | ||
1821 | 152 | <h1> | ||
1822 | 153 | <field name="name" /> | ||
1823 | 154 | </h1> | ||
1824 | 155 | </div> | ||
1825 | 156 | <group> | ||
1826 | 157 | <field name="description" /> | ||
1827 | 158 | <field name="sequence" /> | ||
1828 | 159 | <field name="allow_custom_value" /> | ||
1829 | 160 | <field name="mandatory_dimension" /> | ||
1830 | 161 | <field name="option_ids" nolabel="1" colspan="4"/> | ||
1831 | 162 | </group> | ||
1832 | 163 | </sheet> | ||
1833 | 164 | </form> | ||
1834 | 165 | </field> | ||
1835 | 166 | </record> | ||
1836 | 167 | |||
1837 | 168 | |||
1838 | 169 | <record id="action_dimension_type" model="ir.actions.act_window"> | ||
1839 | 170 | <field name="name">Dimension Types</field> | ||
1840 | 171 | <field name="res_model">product.variant.dimension.type</field> | ||
1841 | 172 | <field name="view_type">form</field> | ||
1842 | 173 | <field name="view_mode">tree,form</field> | ||
1843 | 174 | <field name="context">{'dimension_type_main_view': True}</field> | ||
1844 | 175 | </record> | ||
1845 | 176 | |||
1846 | 177 | <menuitem id="menu_variant_dimension_types" parent="menu_variant_dimension" action="action_dimension_type" /> | ||
1847 | 178 | |||
1861 | 179 | 62 | ||
1862 | 180 | <!-- PRODUCT TEMPLATE --> | 63 | <!-- PRODUCT TEMPLATE --> |
1863 | 181 | |||
1864 | 182 | <!-- TODO remove useless view of product.template in the module product or fusion this view with the existing view in product, it's depend how the inheritage on this view will be managed by the other module--> | ||
1865 | 183 | |||
1866 | 184 | <!--TODO add a wizard to add the option--> | ||
1867 | 185 | <!--<button name="add_some_option" string="Add " type="object" colspan="2"/>--> | ||
1868 | 186 | |||
1869 | 187 | <record id="product_search_form_view_template" model="ir.ui.view"> | ||
1870 | 188 | <field name="name">product.search.form.template</field> | ||
1871 | 189 | <field name="model">product.template</field> | ||
1872 | 190 | <field name="arch" type="xml"> | ||
1873 | 191 | <search string="Product Template"> | ||
1874 | 192 | <field name="name"/> | ||
1875 | 193 | </search> | ||
1876 | 194 | </field> | ||
1877 | 195 | </record> | ||
1878 | 196 | |||
1879 | 197 | <record id="product_variant_multi_product_template_form_view" model="ir.ui.view"> | 64 | <record id="product_variant_multi_product_template_form_view" model="ir.ui.view"> |
1880 | 198 | <field name="name">product.variant.multi.product.template.form</field> | ||
1881 | 199 | <field name="model">product.template</field> | 65 | <field name="model">product.template</field> |
1882 | 200 | <field name="inherit_id" ref="product.product_template_form_view" /> | 66 | <field name="inherit_id" ref="product.product_template_form_view" /> |
1883 | 201 | <field name="arch" type="xml"> | 67 | <field name="arch" type="xml"> |
1884 | 202 | <xpath expr="//field[@name='categ_id']/.." position="after"> | 68 | <xpath expr="//field[@name='categ_id']/.." position="after"> |
1885 | 203 | <group> | 69 | <group> |
1886 | 204 | <field name="is_multi_variants"/> | 70 | <field name="is_multi_variants"/> |
1887 | 71 | <field name="attribute_set_id" | ||
1888 | 72 | attrs="{'invisible':[('is_multi_variants','=',False)]}"/> | ||
1889 | 205 | </group> | 73 | </group> |
1890 | 206 | </xpath> | 74 | </xpath> |
1891 | 207 | <xpath expr="//form/notebook" position="inside"> | 75 | <xpath expr="//form/notebook" position="inside"> |
1892 | 208 | <page string="Variants"> | 76 | <page string="Variants"> |
1893 | 209 | <group colspan="1" col="4" attrs="{'invisible':[('is_multi_variants','=',False)]}"> | 77 | <group colspan="1" col="4" attrs="{'invisible':[('is_multi_variants','=',False)]}"> |
1900 | 210 | <field name="dimension_type_ids" nolabel="1" colspan="4" /> | 78 | <button name="%(product_variant_generator.action_add_option)d" |
1901 | 211 | <button name="add_all_option" string="Add All Options" type="object" colspan="2"/> | 79 | string="Add Option" |
1902 | 212 | <field name="value_ids" nolabel="1" colspan="4" /> | 80 | type="action"/> |
1903 | 213 | <field name="variant_model_name" colspan="4"/> | 81 | <field name="value_ids" nolabel="1" colspan="4"> |
1904 | 214 | <field name="variant_model_name_separator" colspan="4"/> | 82 | <tree string="Values" editable="top"> |
1905 | 215 | <field name="code_generator" colspan="4"/> | 83 | <field name="active"/> |
1906 | 84 | <field name="dimension_id" | ||
1907 | 85 | on_change="on_dimension_change(dimension_id, context)" | ||
1908 | 86 | domain="[('dimension_id','in',parent.dimension_ids)]" /> | ||
1909 | 87 | <field name="option_id"/> | ||
1910 | 88 | </tree> | ||
1911 | 89 | </field> | ||
1912 | 90 | <field name="base_default_code" colspan="4"/> | ||
1913 | 91 | <field name="template_name_id" colspan="4"/> | ||
1914 | 92 | <field name="template_code_id" colspan="4"/> | ||
1915 | 216 | <field name="variant_track_production" colspan="4"/> | 93 | <field name="variant_track_production" colspan="4"/> |
1916 | 217 | <field name="variant_track_incoming" colspan="4"/> | 94 | <field name="variant_track_incoming" colspan="4"/> |
1917 | 218 | <field name="variant_track_outgoing" colspan="4"/> | 95 | <field name="variant_track_outgoing" colspan="4"/> |
1918 | 219 | <field name="do_not_generate_new_variant" colspan="4"/> | 96 | <field name="do_not_generate_new_variant" colspan="4"/> |
1919 | 220 | <field name="do_not_update_variant" colspan="4"/> | 97 | <field name="do_not_update_variant" colspan="4"/> |
1921 | 221 | <button name="button_generate_variants" string="Generate / Update Variants" type="object" colspan="4"/> | 98 | <button name="button_generate_variants" |
1922 | 99 | string="Generate / Update Variants" | ||
1923 | 100 | type="object" | ||
1924 | 101 | colspan="4"/> | ||
1925 | 222 | </group> | 102 | </group> |
1927 | 223 | <field name="variant_ids" string="Variants" nolabel="1" colspan="1"> | 103 | <separator string="Variants"/> |
1928 | 104 | <field name="variant_ids" | ||
1929 | 105 | string="Variants" | ||
1930 | 106 | nolabel="1" | ||
1931 | 107 | colspan="1"> | ||
1932 | 224 | <tree string="Variants"> | 108 | <tree string="Variants"> |
1933 | 225 | <field name="code" /> | 109 | <field name="code" /> |
1934 | 226 | <field name="name" /> | 110 | <field name="name" /> |
1935 | @@ -240,27 +124,8 @@ | |||
1936 | 240 | <field name="view_mode">tree,form</field> | 124 | <field name="view_mode">tree,form</field> |
1937 | 241 | </record> | 125 | </record> |
1938 | 242 | 126 | ||
1939 | 243 | <menuitem action="product_template" id="menu_template" parent="product.prod_config_main" /> | ||
1940 | 244 | |||
1941 | 245 | |||
1942 | 246 | <!-- PRODUCT VARIANTS --> | 127 | <!-- PRODUCT VARIANTS --> |
1943 | 247 | |||
1944 | 248 | <!-- TODO remove useless view of product.product in the module product or move this correct view in product, it's depend how the heritage on this view will be managed by the other module --> | ||
1945 | 249 | |||
1946 | 250 | <record id="product_search_form_view_variants" model="ir.ui.view"> | ||
1947 | 251 | <field name="name">product.search.form.variants</field> | ||
1948 | 252 | <field name="model">product.product</field> | ||
1949 | 253 | <field name="inherit_id" ref="product.product_search_form_view"/> | ||
1950 | 254 | <field name="arch" type="xml"> | ||
1951 | 255 | <field name="categ_id" position="after"> | ||
1952 | 256 | <field name="product_tmpl_id"/> | ||
1953 | 257 | <field name="variants"/> | ||
1954 | 258 | </field> | ||
1955 | 259 | </field> | ||
1956 | 260 | </record> | ||
1957 | 261 | |||
1958 | 262 | <record id="product_variant_form_view" model="ir.ui.view"> | 128 | <record id="product_variant_form_view" model="ir.ui.view"> |
1959 | 263 | <field name="name">product.variant.form</field> | ||
1960 | 264 | <field name="model">product.product</field> | 129 | <field name="model">product.product</field> |
1961 | 265 | <field name="arch" type="xml"> | 130 | <field name="arch" type="xml"> |
1962 | 266 | <form string="Product Variant" version="7.0"> | 131 | <form string="Product Variant" version="7.0"> |
1963 | @@ -280,27 +145,12 @@ | |||
1964 | 280 | <field name="default_code" /> | 145 | <field name="default_code" /> |
1965 | 281 | <field name="active" /> | 146 | <field name="active" /> |
1966 | 282 | </group> | 147 | </group> |
1967 | 283 | <notebook colspan="4"> | ||
1968 | 284 | <page string="Dimensions"> | ||
1969 | 285 | <separator string="Dimension Values" colspan="4"/> | ||
1970 | 286 | <field name="dimension_value_ids" context="{'product_tmpl_id':product_tmpl_id}" nolabel="1" colspan="4"/> | ||
1971 | 287 | </page> | ||
1972 | 288 | <page string="Prices"> | ||
1973 | 289 | <group> | ||
1974 | 290 | <field name="list_price" string="Template Sale Price" readonly="1"/> | ||
1975 | 291 | <field name="price_margin" /> | ||
1976 | 292 | <field name="price_extra" /> | ||
1977 | 293 | <field name="cost_price_extra"/> | ||
1978 | 294 | </group> | ||
1979 | 295 | </page> | ||
1980 | 296 | </notebook> | ||
1981 | 297 | </sheet> | 148 | </sheet> |
1982 | 298 | </form> | 149 | </form> |
1983 | 299 | </field> | 150 | </field> |
1984 | 300 | </record> | 151 | </record> |
1985 | 301 | 152 | ||
1986 | 302 | <record id="product_variant_tree_view" model="ir.ui.view"> | 153 | <record id="product_variant_tree_view" model="ir.ui.view"> |
1987 | 303 | <field name="name">product.variant.tree</field> | ||
1988 | 304 | <field name="model">product.product</field> | 154 | <field name="model">product.product</field> |
1989 | 305 | <field name="arch" type="xml"> | 155 | <field name="arch" type="xml"> |
1990 | 306 | <tree string="Product Variant"> | 156 | <tree string="Product Variant"> |
1991 | @@ -308,37 +158,11 @@ | |||
1992 | 308 | <field name="name"/> | 158 | <field name="name"/> |
1993 | 309 | <field name="product_tmpl_id"/> | 159 | <field name="product_tmpl_id"/> |
1994 | 310 | <field name="variants"/> | 160 | <field name="variants"/> |
1995 | 311 | <field name="price_extra"/> | ||
1996 | 312 | <field name="cost_price_extra"/> | ||
1997 | 313 | </tree> | 161 | </tree> |
1998 | 314 | </field> | 162 | </field> |
1999 | 315 | </record> | 163 | </record> |
2000 | 316 | 164 | ||
2001 | 317 | <record id="product_variant" model="ir.actions.act_window"> | ||
2002 | 318 | <field name="name">Product Variants</field> | ||
2003 | 319 | <field name="res_model">product.product</field> | ||
2004 | 320 | <field name="view_type">form</field> | ||
2005 | 321 | <field name="view_mode">tree,form</field> | ||
2006 | 322 | </record> | ||
2007 | 323 | |||
2008 | 324 | <record id="action_variant_tree" model="ir.actions.act_window.view"> | ||
2009 | 325 | <field name="sequence" eval="10" /> | ||
2010 | 326 | <field name="view_mode">tree</field> | ||
2011 | 327 | <field name="act_window_id" ref="product_variant" /> | ||
2012 | 328 | <field name="view_id" ref="product_variant_tree_view" /> | ||
2013 | 329 | </record> | ||
2014 | 330 | |||
2015 | 331 | <record id="action_variant_form" model="ir.actions.act_window.view"> | ||
2016 | 332 | <field name="sequence" eval="20" /> | ||
2017 | 333 | <field name="view_mode">form</field> | ||
2018 | 334 | <field name="act_window_id" ref="product_variant" /> | ||
2019 | 335 | <field name="view_id" ref="product_variant_form_view" /> | ||
2020 | 336 | </record> | ||
2021 | 337 | |||
2022 | 338 | <menuitem action="product_variant" id="menu_variant" parent="product.prod_config_main" /> | ||
2023 | 339 | |||
2024 | 340 | <record id="product_normal_variant_form_view" model="ir.ui.view"> | 165 | <record id="product_normal_variant_form_view" model="ir.ui.view"> |
2025 | 341 | <field name="name">product.normal.variant.form</field> | ||
2026 | 342 | <field name="model">product.product</field> | 166 | <field name="model">product.product</field> |
2027 | 343 | <field name="inherit_id" ref="product.product_normal_form_view" /> | 167 | <field name="inherit_id" ref="product.product_normal_form_view" /> |
2028 | 344 | <field name="arch" type="xml"> | 168 | <field name="arch" type="xml"> |
2029 | @@ -349,33 +173,54 @@ | |||
2030 | 349 | <field name="is_multi_variants" readonly="1"/> | 173 | <field name="is_multi_variants" readonly="1"/> |
2031 | 350 | <label for="is_multi_variants" /> | 174 | <label for="is_multi_variants" /> |
2032 | 351 | </div> | 175 | </div> |
2060 | 352 | <field name="standard_price" position="replace"> | 176 | </field> |
2061 | 353 | <group name='cost_prices' colspan="2" col="2"> | 177 | </record> |
2062 | 354 | <field name="standard_price" attrs="{'readonly':[('cost_method','=','average')]}"/> | 178 | |
2063 | 355 | <field name="cost_price_extra" groups="product.group_product_variant"/> | 179 | <record id="view_model_string_template_search" model="ir.ui.view"> |
2064 | 356 | </group> | 180 | <field name="model">string.template</field> |
2065 | 357 | </field> | 181 | <field name="arch" type="xml"> |
2066 | 358 | <group name="Weights" position="replace"> | 182 | <search string="String Template"> |
2067 | 359 | <group colspan="4" col="6" name="Weights" groups="product.group_stock_packaging"> | 183 | <field name="name"/> |
2068 | 360 | <group name="template_weights" string="Template Weights"> | 184 | </search> |
2069 | 361 | <field digits="(14, 3)" name="volume" attrs="{'readonly':[('type','=','service')]}"/> | 185 | </field> |
2070 | 362 | <field name="weight" attrs="{'readonly':[('type','=','service')]}"/> | 186 | </record> |
2071 | 363 | <field name="weight_net" attrs="{'readonly':[('type','=','service')]}"/> | 187 | |
2072 | 364 | </group> | 188 | <record id="view_model_string_template_tree" model="ir.ui.view"> |
2073 | 365 | <group name="variant_weights" string="Variant Weights" attrs="{'invisible':[('is_multi_variants','=',False)]}"> | 189 | <field name="model">string.template</field> |
2074 | 366 | <field digits="(14, 3)" name="additional_volume" attrs="{'readonly':[('type','=','service')]}"/> | 190 | <field name="arch" type="xml"> |
2075 | 367 | <field name="additional_weight" attrs="{'readonly':[('type','=','service')]}"/> | 191 | <tree string="String Template"> |
2076 | 368 | <field name="additional_weight_net" attrs="{'readonly':[('type','=','service')]}"/> | 192 | <field name="name"/> |
2077 | 369 | </group> | 193 | <field name="type"/> |
2078 | 370 | <group name="total_weights" string="Total Weights" attrs="{'invisible':[('is_multi_variants','=',False)]}"> | 194 | </tree> |
2079 | 371 | <field digits="(14, 3)" name="total_volume"/> | 195 | </field> |
2080 | 372 | <field name="total_weight"/> | 196 | </record> |
2081 | 373 | <field name="total_weight_net"/> | 197 | |
2082 | 374 | </group> | 198 | <record id="view_model_string_template_form" model="ir.ui.view"> |
2083 | 375 | </group> | 199 | <field name="model">string.template</field> |
2084 | 376 | </group> | 200 | <field name="arch" type="xml"> |
2085 | 377 | </field> | 201 | <form string="Label" version="7.0"> |
2086 | 378 | </record> | 202 | <field name="name"/> |
2087 | 203 | <field name="type"/> | ||
2088 | 204 | <field name="code"/> | ||
2089 | 205 | </form> | ||
2090 | 206 | </field> | ||
2091 | 207 | </record> | ||
2092 | 208 | |||
2093 | 209 | <record id="string_template_form_action" model="ir.actions.act_window"> | ||
2094 | 210 | <field name="res_model">string.template</field> | ||
2095 | 211 | <field name="view_type">form</field> | ||
2096 | 212 | <field name="view_mode">tree,form</field> | ||
2097 | 213 | <field name="view_id" ref="view_model_string_template_tree"/> | ||
2098 | 214 | <field name="search_view_id" ref="view_model_string_template_search"/> | ||
2099 | 215 | <field name="help"></field> | ||
2100 | 216 | </record> | ||
2101 | 217 | |||
2102 | 218 | <menuitem | ||
2103 | 219 | name="Product Code/Name generator" | ||
2104 | 220 | action="string_template_form_action" | ||
2105 | 221 | id="menu_string_template_action" | ||
2106 | 222 | parent="product.prod_config_main" | ||
2107 | 223 | sequence="40"/> | ||
2108 | 379 | 224 | ||
2109 | 380 | </data> | 225 | </data> |
2110 | 381 | </openerp> | 226 | </openerp> |
2111 | 382 | 227 | ||
2112 | === modified file 'product_variant_generator/security/ir.model.access.csv' | |||
2113 | --- product_variant_multi/security/ir.model.access.csv 2013-04-22 21:00:07 +0000 | |||
2114 | +++ product_variant_generator/security/ir.model.access.csv 2014-06-24 09:37:35 +0000 | |||
2115 | @@ -1,7 +1,3 @@ | |||
2116 | 1 | "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" | 1 | "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" |
2123 | 2 | "access_product_variant_dimension_type_user","Read access on product.variant.dimension.type for employees","model_product_variant_dimension_type","base.group_user",1,0,0,0 | 2 | "access_dimension_value_user","Read access on dimension.value for employees","model_dimension_value","base.group_user",1,0,0,0 |
2124 | 3 | "access_product_variant_dimension_value_user","Read access on product.variant.dimension.value for employees","model_product_variant_dimension_value","base.group_user",1,0,0,0 | 3 | "access_dimension_value_sale_manager","Full rights on dimension.value for sale manager","model_dimension_value","base.group_sale_manager",1,1,1,1 |
2119 | 4 | "access_product_variant_dimension_option_user","Read access on product.variant.dimension.option for employees","model_product_variant_dimension_option","base.group_user",1,0,0,0 | ||
2120 | 5 | "access_product_variant_dimension_type_sale_manager","Full rights on product.variant.dimension.type for sale manager","model_product_variant_dimension_type","base.group_sale_manager",1,1,1,1 | ||
2121 | 6 | "access_product_variant_dimension_value_sale_manager","Full rights on product.variant.dimension.value for sale manager","model_product_variant_dimension_value","base.group_sale_manager",1,1,1,1 | ||
2122 | 7 | "access_product_variant_dimension_option_sale_manager","Full rights on product.variant.dimension.option for sale manager","model_product_variant_dimension_option","base.group_sale_manager",1,1,1,1 | ||
2125 | 8 | 4 | ||
2126 | === added directory 'product_variant_generator/wizard' | |||
2127 | === added file 'product_variant_generator/wizard/__init__.py' | |||
2128 | --- product_variant_generator/wizard/__init__.py 1970-01-01 00:00:00 +0000 | |||
2129 | +++ product_variant_generator/wizard/__init__.py 2014-06-24 09:37:35 +0000 | |||
2130 | @@ -0,0 +1,24 @@ | |||
2131 | 1 | # -*- coding: utf-8 -*- | ||
2132 | 2 | ############################################################################### | ||
2133 | 3 | # | ||
2134 | 4 | # Module for OpenERP | ||
2135 | 5 | # Copyright (C) 2014 Akretion (http://www.akretion.com). | ||
2136 | 6 | # @author Sébastien BEAU <sebastien.beau@akretion.com> | ||
2137 | 7 | # | ||
2138 | 8 | # This program is free software: you can redistribute it and/or modify | ||
2139 | 9 | # it under the terms of the GNU Affero General Public License as | ||
2140 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
2141 | 11 | # License, or (at your option) any later version. | ||
2142 | 12 | # | ||
2143 | 13 | # This program is distributed in the hope that it will be useful, | ||
2144 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2145 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2146 | 16 | # GNU Affero General Public License for more details. | ||
2147 | 17 | # | ||
2148 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
2149 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2150 | 20 | # | ||
2151 | 21 | ############################################################################### | ||
2152 | 22 | |||
2153 | 23 | from . import product_template_add_option | ||
2154 | 24 | |||
2155 | 0 | 25 | ||
2156 | === added file 'product_variant_generator/wizard/product_template_add_option.py' | |||
2157 | --- product_variant_generator/wizard/product_template_add_option.py 1970-01-01 00:00:00 +0000 | |||
2158 | +++ product_variant_generator/wizard/product_template_add_option.py 2014-06-24 09:37:35 +0000 | |||
2159 | @@ -0,0 +1,69 @@ | |||
2160 | 1 | # -*- coding: utf-8 -*- | ||
2161 | 2 | ############################################################################### | ||
2162 | 3 | # | ||
2163 | 4 | # Module for OpenERP | ||
2164 | 5 | # Copyright (C) 2014 Akretion (http://www.akretion.com). | ||
2165 | 6 | # @author Sébastien BEAU <sebastien.beau@akretion.com> | ||
2166 | 7 | # | ||
2167 | 8 | # This program is free software: you can redistribute it and/or modify | ||
2168 | 9 | # it under the terms of the GNU Affero General Public License as | ||
2169 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
2170 | 11 | # License, or (at your option) any later version. | ||
2171 | 12 | # | ||
2172 | 13 | # This program is distributed in the hope that it will be useful, | ||
2173 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2174 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2175 | 16 | # GNU Affero General Public License for more details. | ||
2176 | 17 | # | ||
2177 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
2178 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2179 | 20 | # | ||
2180 | 21 | ############################################################################### | ||
2181 | 22 | |||
2182 | 23 | from openerp.osv import fields, orm | ||
2183 | 24 | |||
2184 | 25 | |||
2185 | 26 | class ProductTemplateAddOption(orm.TransientModel): | ||
2186 | 27 | _name = 'product.template.add.option' | ||
2187 | 28 | _description = 'Product Template Add Option' | ||
2188 | 29 | |||
2189 | 30 | def _get_option_domain(self, cr, uid, tmpl, context=None): | ||
2190 | 31 | domain = [('attribute_id', 'in', [x.id for x in tmpl.dimension_ids])] | ||
2191 | 32 | existing_option_ids = [value.option_id.id for value in tmpl.value_ids] | ||
2192 | 33 | if existing_option_ids: | ||
2193 | 34 | domain.append(('id', 'not in', existing_option_ids)) | ||
2194 | 35 | return domain | ||
2195 | 36 | |||
2196 | 37 | def fields_view_get(self, cr, uid, view_id=None, view_type='form', | ||
2197 | 38 | context=None, toolbar=False, submenu=False): | ||
2198 | 39 | res = super(ProductTemplateAddOption, self).fields_view_get( | ||
2199 | 40 | cr, uid, view_id=view_id, view_type=view_type, | ||
2200 | 41 | context=context, toolbar=toolbar, submenu=submenu, | ||
2201 | 42 | ) | ||
2202 | 43 | tmpl_id = context.get('active_id') | ||
2203 | 44 | if tmpl_id and view_type == 'form': | ||
2204 | 45 | tmpl_obj = self.pool['product.template'] | ||
2205 | 46 | tmpl = tmpl_obj.browse(cr, uid, tmpl_id, context=context) | ||
2206 | 47 | res['fields']['option_ids']['domain'] = self._get_option_domain( | ||
2207 | 48 | cr, uid, tmpl, context=context) | ||
2208 | 49 | return res | ||
2209 | 50 | |||
2210 | 51 | _columns = { | ||
2211 | 52 | 'option_ids': fields.many2many( | ||
2212 | 53 | 'attribute.option', | ||
2213 | 54 | string='Option'), | ||
2214 | 55 | } | ||
2215 | 56 | |||
2216 | 57 | def add_option(self, cr, uid, ids, context=None): | ||
2217 | 58 | tmpl_obj = self.pool['product.template'] | ||
2218 | 59 | for wizard in self.browse(cr, uid, ids, context=context): | ||
2219 | 60 | values = [] | ||
2220 | 61 | for option in wizard.option_ids: | ||
2221 | 62 | values.append([0, 0, { | ||
2222 | 63 | 'dimension_id': option.attribute_id.id, | ||
2223 | 64 | 'option_id': option.id, | ||
2224 | 65 | }]) | ||
2225 | 66 | tmpl_obj.write(cr, uid, context['active_id'], { | ||
2226 | 67 | 'value_ids': values, | ||
2227 | 68 | }, context=context) | ||
2228 | 69 | return True | ||
2229 | 0 | 70 | ||
2230 | === added file 'product_variant_generator/wizard/product_template_add_option_view.xml' | |||
2231 | --- product_variant_generator/wizard/product_template_add_option_view.xml 1970-01-01 00:00:00 +0000 | |||
2232 | +++ product_variant_generator/wizard/product_template_add_option_view.xml 2014-06-24 09:37:35 +0000 | |||
2233 | @@ -0,0 +1,29 @@ | |||
2234 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2235 | 2 | <openerp> | ||
2236 | 3 | <data> | ||
2237 | 4 | |||
2238 | 5 | <record id="action_add_option" model="ir.actions.act_window"> | ||
2239 | 6 | <field name="name">Add Option</field> | ||
2240 | 7 | <field name="res_model">product.template.add.option</field> | ||
2241 | 8 | <field name="view_type">form</field> | ||
2242 | 9 | <field name="view_mode">form</field> | ||
2243 | 10 | <field name="target">new</field> | ||
2244 | 11 | </record> | ||
2245 | 12 | |||
2246 | 13 | <record id="view_product_template_add_option_form" model="ir.ui.view"> | ||
2247 | 14 | <field name="model">product.template.add.option</field> | ||
2248 | 15 | <field name="arch" type="xml"> | ||
2249 | 16 | <form string="Add Option" version="7.0"> | ||
2250 | 17 | <field name="option_ids"/> | ||
2251 | 18 | <footer> | ||
2252 | 19 | <button name="add_option" string="Confirm" type="object" class="oe_highlight"/> | ||
2253 | 20 | or | ||
2254 | 21 | <button string="Cancel" class="oe_link" special="cancel" /> | ||
2255 | 22 | </footer> | ||
2256 | 23 | |||
2257 | 24 | </form> | ||
2258 | 25 | </field> | ||
2259 | 26 | </record> | ||
2260 | 27 | |||
2261 | 28 | </data> | ||
2262 | 29 | </openerp> | ||
2263 | 0 | 30 | ||
2264 | === added directory 'product_variant_generator_price' | |||
2265 | === added file 'product_variant_generator_price/__init__.py' | |||
2266 | --- product_variant_generator_price/__init__.py 1970-01-01 00:00:00 +0000 | |||
2267 | +++ product_variant_generator_price/__init__.py 2014-06-24 09:37:35 +0000 | |||
2268 | @@ -0,0 +1,23 @@ | |||
2269 | 1 | # -*- encoding: utf-8 -*- | ||
2270 | 2 | ############################################################################## | ||
2271 | 3 | # | ||
2272 | 4 | # OpenERP, Open Source Management Solution | ||
2273 | 5 | # Copyright (C) 2014 Akretion (http://www.akretion.com) | ||
2274 | 6 | # | ||
2275 | 7 | # This program is free software: you can redistribute it and/or modify | ||
2276 | 8 | # it under the terms of the GNU General Public License as published by | ||
2277 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
2278 | 10 | # (at your option) any later version. | ||
2279 | 11 | # | ||
2280 | 12 | # This program is distributed in the hope that it will be useful, | ||
2281 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2282 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2283 | 15 | # GNU General Public License for more details. | ||
2284 | 16 | # | ||
2285 | 17 | # You should have received a copy of the GNU General Public License | ||
2286 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2287 | 19 | # | ||
2288 | 20 | ############################################################################## | ||
2289 | 21 | # flake8: noqa | ||
2290 | 22 | |||
2291 | 23 | from . import product_variant | ||
2292 | 0 | 24 | ||
2293 | === added file 'product_variant_generator_price/__openerp__.py' | |||
2294 | --- product_variant_generator_price/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
2295 | +++ product_variant_generator_price/__openerp__.py 2014-06-24 09:37:35 +0000 | |||
2296 | @@ -0,0 +1,40 @@ | |||
2297 | 1 | # -*- encoding: utf-8 -*- | ||
2298 | 2 | ############################################################################## | ||
2299 | 3 | # | ||
2300 | 4 | # OpenERP, Open Source Management Solution | ||
2301 | 5 | # Copyright (C) 2014 Akretion (http://www.akretion.com) | ||
2302 | 6 | # | ||
2303 | 7 | # This program is free software: you can redistribute it and/or modify | ||
2304 | 8 | # it under the terms of the GNU General Public License as published by | ||
2305 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
2306 | 10 | # (at your option) any later version. | ||
2307 | 11 | # | ||
2308 | 12 | # This program is distributed in the hope that it will be useful, | ||
2309 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2310 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2311 | 15 | # GNU General Public License for more details. | ||
2312 | 16 | # | ||
2313 | 17 | # You should have received a copy of the GNU General Public License | ||
2314 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2315 | 19 | # | ||
2316 | 20 | ############################################################################## | ||
2317 | 21 | { | ||
2318 | 22 | "name": "Product Variant Generator Price", | ||
2319 | 23 | "version": "1.0", | ||
2320 | 24 | "author": "OpenERP SA, Akretion", | ||
2321 | 25 | "category": "Sales Management", | ||
2322 | 26 | "license": "AGPL-3", | ||
2323 | 27 | "summary": "Product Prices with multi-dimension variants", | ||
2324 | 28 | "description": """ | ||
2325 | 29 | |||
2326 | 30 | """, | ||
2327 | 31 | "depends" : [ | ||
2328 | 32 | "product_variant_generator", | ||
2329 | 33 | ], | ||
2330 | 34 | "data" : [ | ||
2331 | 35 | "product_view.xml", | ||
2332 | 36 | ], | ||
2333 | 37 | "application": True, | ||
2334 | 38 | "active": False, | ||
2335 | 39 | "installable": True, | ||
2336 | 40 | } | ||
2337 | 0 | 41 | ||
2338 | === added file 'product_variant_generator_price/product_variant.py' | |||
2339 | --- product_variant_generator_price/product_variant.py 1970-01-01 00:00:00 +0000 | |||
2340 | +++ product_variant_generator_price/product_variant.py 2014-06-24 09:37:35 +0000 | |||
2341 | @@ -0,0 +1,119 @@ | |||
2342 | 1 | # -*- encoding: utf-8 -*- | ||
2343 | 2 | ############################################################################## | ||
2344 | 3 | # | ||
2345 | 4 | # OpenERP, Open Source Management Solution | ||
2346 | 5 | # Copyright (C) 2014 Akretion (www.akretion.com). All Rights Reserved | ||
2347 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
2348 | 7 | # | ||
2349 | 8 | # This program is free software: you can redistribute it and/or modify | ||
2350 | 9 | # it under the terms of the GNU General Public License as published by | ||
2351 | 10 | # the Free Software Foundation, either version 3 of the License, or | ||
2352 | 11 | # (at your option) any later version. | ||
2353 | 12 | # | ||
2354 | 13 | # This program is distributed in the hope that it will be useful, | ||
2355 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2356 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2357 | 16 | # GNU General Public License for more details. | ||
2358 | 17 | # | ||
2359 | 18 | # You should have received a copy of the GNU General Public License | ||
2360 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2361 | 20 | # | ||
2362 | 21 | ############################################################################## | ||
2363 | 22 | |||
2364 | 23 | from openerp.osv import fields, orm | ||
2365 | 24 | |||
2366 | 25 | |||
2367 | 26 | class ProductTemplate(orm.Model): | ||
2368 | 27 | _inherit = "product.template" | ||
2369 | 28 | |||
2370 | 29 | _columns = { | ||
2371 | 30 | 'automatic_price_extra': fields.boolean("Automatic Price Extra"), | ||
2372 | 31 | } | ||
2373 | 32 | |||
2374 | 33 | |||
2375 | 34 | class ProductProduct(orm.Model): | ||
2376 | 35 | _inherit = "product.product" | ||
2377 | 36 | |||
2378 | 37 | def _get_price_extra(self, cr, uid, ids, field_names=None, arg=False, | ||
2379 | 38 | context=None): | ||
2380 | 39 | res = {} | ||
2381 | 40 | for product in self.browse(cr, uid, ids, context=context): | ||
2382 | 41 | price_extra = 0.00 | ||
2383 | 42 | if product.automatic_price_extra: | ||
2384 | 43 | for dimension in product.dimension_ids: | ||
2385 | 44 | option = product[dimension.name] | ||
2386 | 45 | if option: | ||
2387 | 46 | for dimension_value in product.value_ids: | ||
2388 | 47 | if dimension_value.option_id.id == option.id: | ||
2389 | 48 | price_extra += dimension_value.price_extra | ||
2390 | 49 | break | ||
2391 | 50 | else: | ||
2392 | 51 | price_extra = product.manual_price_extra | ||
2393 | 52 | res[product.id] = price_extra | ||
2394 | 53 | return res | ||
2395 | 54 | |||
2396 | 55 | def _set_extra_price(self, cr, uid, ids, field_names=None, value=None, | ||
2397 | 56 | arg=False, context=None): | ||
2398 | 57 | if isinstance(ids, (int, long)): | ||
2399 | 58 | ids = [ids] | ||
2400 | 59 | for product in self.browse(cr, uid, ids, context=context): | ||
2401 | 60 | if not product.automatic_price_extra: | ||
2402 | 61 | self.write( | ||
2403 | 62 | cr, uid, product.id, {'manual_price_extra': value}, | ||
2404 | 63 | context=context) | ||
2405 | 64 | else: | ||
2406 | 65 | price = self._get_price_extra( | ||
2407 | 66 | cr, uid, [product.id], field_names=field_names, arg=arg, | ||
2408 | 67 | context=context)[product.id] | ||
2409 | 68 | cr.execute("""update product_product set | ||
2410 | 69 | price_extra=%s where id=%s""", (price, product.id)) | ||
2411 | 70 | return True | ||
2412 | 71 | |||
2413 | 72 | def _get_products_from_product_template(self, cr, uid, ids, context=None): | ||
2414 | 73 | return self.get_products_from_product_template( | ||
2415 | 74 | cr, uid, ids, context=context) | ||
2416 | 75 | |||
2417 | 76 | def _get_products_from_dimension_value(self, cr, uid, ids, context=None): | ||
2418 | 77 | res = [] | ||
2419 | 78 | for value in self.browse(cr, uid, ids, context=context): | ||
2420 | 79 | res += self.pool['product.product'].search(cr, uid, | ||
2421 | 80 | [('product_tmpl_id', '=', value.product_tmpl_id.id), | ||
2422 | 81 | (value.dimension_id.name, '=', value.option_id.id)], | ||
2423 | 82 | context=context) | ||
2424 | 83 | return res | ||
2425 | 84 | |||
2426 | 85 | _columns = { | ||
2427 | 86 | 'price_extra': fields.function( | ||
2428 | 87 | _get_price_extra, | ||
2429 | 88 | type='float', | ||
2430 | 89 | fnct_inv=_set_extra_price, | ||
2431 | 90 | string='Price Extra', | ||
2432 | 91 | store ={ | ||
2433 | 92 | 'product.product': ( | ||
2434 | 93 | lambda self, cr, uid, ids, c={}: ids, | ||
2435 | 94 | ['product_tmpl_id', 'manual_price_extra'], | ||
2436 | 95 | 10), | ||
2437 | 96 | 'product.template': ( | ||
2438 | 97 | _get_products_from_product_template, | ||
2439 | 98 | ['automatic_price_extra'], | ||
2440 | 99 | 10), | ||
2441 | 100 | 'dimension.value': ( | ||
2442 | 101 | _get_products_from_dimension_value, | ||
2443 | 102 | ['price_extra'], | ||
2444 | 103 | 10) | ||
2445 | 104 | }, | ||
2446 | 105 | ), | ||
2447 | 106 | 'manual_price_extra': fields.float('Manual Price Extra'), | ||
2448 | 107 | } | ||
2449 | 108 | |||
2450 | 109 | |||
2451 | 110 | class DimensionValue(orm.Model): | ||
2452 | 111 | _inherit = "dimension.value" | ||
2453 | 112 | |||
2454 | 113 | _columns = { | ||
2455 | 114 | 'price_extra': fields.float('Price Extra'), | ||
2456 | 115 | } | ||
2457 | 116 | |||
2458 | 117 | _defaults = { | ||
2459 | 118 | 'price_extra': 0, | ||
2460 | 119 | } | ||
2461 | 0 | 120 | ||
2462 | === added file 'product_variant_generator_price/product_view.xml' | |||
2463 | --- product_variant_generator_price/product_view.xml 1970-01-01 00:00:00 +0000 | |||
2464 | +++ product_variant_generator_price/product_view.xml 2014-06-24 09:37:35 +0000 | |||
2465 | @@ -0,0 +1,79 @@ | |||
2466 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
2467 | 2 | <openerp> | ||
2468 | 3 | <data> | ||
2469 | 4 | |||
2470 | 5 | <!-- | ||
2471 | 6 | "Product variant generator price" module for OpenERP | ||
2472 | 7 | The licence is in the file __openerp__.py | ||
2473 | 8 | @author Chafique Delli <chafique.delli@akretion.com> | ||
2474 | 9 | --> | ||
2475 | 10 | |||
2476 | 11 | <!-- PRODUCT TEMPLATE --> | ||
2477 | 12 | <record id="product_variant_price_product_template_form_view" model="ir.ui.view"> | ||
2478 | 13 | <field name="name">product.variant.price.product.template.form</field> | ||
2479 | 14 | <field name="model">product.template</field> | ||
2480 | 15 | <field name="inherit_id" ref="product_variant_generator.product_variant_multi_product_template_form_view"/> | ||
2481 | 16 | <field name="arch" type="xml"> | ||
2482 | 17 | <field name="option_id" position="after"> | ||
2483 | 18 | <field name="price_extra"/> | ||
2484 | 19 | </field> | ||
2485 | 20 | <xpath expr="//field[@name='variant_ids']/tree[@string='Variants']/field[@name='variants']" position="after"> | ||
2486 | 21 | <field name="price_extra"/> | ||
2487 | 22 | </xpath> | ||
2488 | 23 | <field name="attribute_set_id" position="after"> | ||
2489 | 24 | <field name="automatic_price_extra" | ||
2490 | 25 | attrs="{'invisible':[('is_multi_variants', '=', False)]}"/> | ||
2491 | 26 | </field> | ||
2492 | 27 | </field> | ||
2493 | 28 | </record> | ||
2494 | 29 | |||
2495 | 30 | <!-- PRODUCT PRODUCT --> | ||
2496 | 31 | <record id="product_variant_price_product_normal_form_view" model="ir.ui.view"> | ||
2497 | 32 | <field name="name">product.variant.price.product.normal.form</field> | ||
2498 | 33 | <field name="model">product.product</field> | ||
2499 | 34 | <field name="inherit_id" ref="product.product_normal_form_view"/> | ||
2500 | 35 | <field name="arch" type="xml"> | ||
2501 | 36 | <field name="list_price" position="replace"> | ||
2502 | 37 | <field name="lst_price" string="Sale Price"/> | ||
2503 | 38 | </field> | ||
2504 | 39 | <field name="price_margin" position="replace"> | ||
2505 | 40 | <field name="list_price" string="Base Price"/> | ||
2506 | 41 | </field> | ||
2507 | 42 | <div name="options" position="inside"> | ||
2508 | 43 | <field name="automatic_price_extra" invisible="True"/> | ||
2509 | 44 | </div> | ||
2510 | 45 | <field name="price_extra" position="replace"> | ||
2511 | 46 | <field name="price_extra" | ||
2512 | 47 | attrs="{'readonly':[('automatic_price_extra', '=', True)]}"/> | ||
2513 | 48 | </field> | ||
2514 | 49 | </field> | ||
2515 | 50 | </record> | ||
2516 | 51 | |||
2517 | 52 | <!-- PRODUCT VARIANT --> | ||
2518 | 53 | <record id="product_variant_form_view" model="ir.ui.view"> | ||
2519 | 54 | <field name="model">product.product</field> | ||
2520 | 55 | <field name="inherit_id" ref="product.product_variant_form_view"/> | ||
2521 | 56 | <field name="arch" type="xml"> | ||
2522 | 57 | <field name="price_extra" position="after"> | ||
2523 | 58 | <field name="automatic_price_extra" invisible="True"/> | ||
2524 | 59 | </field> | ||
2525 | 60 | <field name="price_extra" position="replace"> | ||
2526 | 61 | <field name="price_extra" | ||
2527 | 62 | attrs="{'readonly':[('automatic_price_extra', '=', True)]}"/> | ||
2528 | 63 | </field> | ||
2529 | 64 | </field> | ||
2530 | 65 | </record> | ||
2531 | 66 | |||
2532 | 67 | <!-- DIMENSION VALUES --> | ||
2533 | 68 | <record id="product_variant_multi_dimension_value_form" model="ir.ui.view"> | ||
2534 | 69 | <field name="model">dimension.value</field> | ||
2535 | 70 | <field name="inherit_id" ref="product_variant_generator.product_variant_multi_dimension_value_form"/> | ||
2536 | 71 | <field name="arch" type="xml"> | ||
2537 | 72 | <field name="option_id" position="after"> | ||
2538 | 73 | <field name="price_extra"/> | ||
2539 | 74 | </field> | ||
2540 | 75 | </field> | ||
2541 | 76 | </record> | ||
2542 | 77 | |||
2543 | 78 | </data> | ||
2544 | 79 | </openerp> | ||
2545 | 0 | 80 | ||
2546 | === removed file 'product_variant_multi/demo_data.xml' | |||
2547 | --- product_variant_multi/demo_data.xml 2011-08-23 07:46:17 +0000 | |||
2548 | +++ product_variant_multi/demo_data.xml 1970-01-01 00:00:00 +0000 | |||
2549 | @@ -1,84 +0,0 @@ | |||
2550 | 1 | <?xml version="1.0" ?> | ||
2551 | 2 | <openerp> | ||
2552 | 3 | |||
2553 | 4 | <data noupdate="1"> | ||
2554 | 5 | <!-- | ||
2555 | 6 | <record id="product_template_mezzanine" model="product.template"> | ||
2556 | 7 | <field eval="1.0" name="list_price"/> | ||
2557 | 8 | <field eval="1.0" name="standard_price"/> | ||
2558 | 9 | <field eval=""""fixed"""" name="mes_type"/> | ||
2559 | 10 | <field name="uom_id" ref="product.product_uom_unit"/> | ||
2560 | 11 | <field eval="1.0" name="uos_coeff"/> | ||
2561 | 12 | <field eval="1" name="sale_ok"/> | ||
2562 | 13 | <field eval="1" name="purchase_ok"/> | ||
2563 | 14 | <field name="company_id" ref="base.main_company"/> | ||
2564 | 15 | <field name="uom_po_id" ref="product.product_uom_unit"/> | ||
2565 | 16 | <field eval=""""product"""" name="type"/> | ||
2566 | 17 | <field eval=""""Mezzanine"""" name="name"/> | ||
2567 | 18 | <field name="cost_method">standard</field> | ||
2568 | 19 | <field name="supply_method">produce</field> | ||
2569 | 20 | <field name="procure_method">make_to_order</field> | ||
2570 | 21 | <field eval="0" name="rental"/> | ||
2571 | 22 | <field eval="7.0" name="sale_delay"/> | ||
2572 | 23 | <field name="categ_id" ref="product.cat1"/> | ||
2573 | 24 | <field eval="1.0" name="produce_delay"/> | ||
2574 | 25 | </record> | ||
2575 | 26 | <record id="product_variant_dimension_type_hauteur0" model="product.variant.dimension.type"> | ||
2576 | 27 | <field name="product_tmpl_id" ref="product_template_mezzanine"/> | ||
2577 | 28 | <field eval="1" name="allow_custom_value"/> | ||
2578 | 29 | <field eval=""""Hauteur"""" name="name"/> | ||
2579 | 30 | <field eval="0" name="sequence"/> | ||
2580 | 31 | </record> | ||
2581 | 32 | <record id="product_variant_dimension_type_largeur0" model="product.variant.dimension.type"> | ||
2582 | 33 | <field name="product_tmpl_id" ref="product_template_mezzanine"/> | ||
2583 | 34 | <field eval="1" name="allow_custom_value"/> | ||
2584 | 35 | <field eval=""""Largeur"""" name="name"/> | ||
2585 | 36 | <field eval="1" name="sequence"/> | ||
2586 | 37 | </record> | ||
2587 | 38 | <record id="product_variant_dimension_value_0" model="product.variant.dimension.value"> | ||
2588 | 39 | <field eval=""""10"""" name="name"/> | ||
2589 | 40 | <field name="dimension_id" ref="product_variant_dimension_type_hauteur0"/> | ||
2590 | 41 | <field model="product.template" name="product_tmpl_id" search="[('name','=','Mezzanine')]"/> | ||
2591 | 42 | </record> | ||
2592 | 43 | <record id="product_variant_dimension_value_1" model="product.variant.dimension.value"> | ||
2593 | 44 | <field eval=""""20"""" name="name"/> | ||
2594 | 45 | <field name="dimension_id" ref="product_variant_dimension_type_hauteur0"/> | ||
2595 | 46 | <field model="product.template" name="product_tmpl_id" search="[('name','=','Mezzanine')]"/> | ||
2596 | 47 | </record> | ||
2597 | 48 | |||
2598 | 49 | <record id="product_variant_dimension_value_2" model="product.variant.dimension.value"> | ||
2599 | 50 | <field eval=""""22"""" name="name"/> | ||
2600 | 51 | <field name="dimension_id" ref="product_variant_dimension_type_largeur0"/> | ||
2601 | 52 | <field eval="1.0" name="dimension_sequence"/> | ||
2602 | 53 | <field model="product.template" name="product_tmpl_id" search="[('name','=','Mezzanine')]"/> | ||
2603 | 54 | </record> | ||
2604 | 55 | <record id="product_variant_dimension_value_3" model="product.variant.dimension.value"> | ||
2605 | 56 | <field eval=""""33"""" name="name"/> | ||
2606 | 57 | <field name="dimension_id" ref="product_variant_dimension_type_largeur0"/> | ||
2607 | 58 | <field eval="1.0" name="dimension_sequence"/> | ||
2608 | 59 | <field model="product.template" name="product_tmpl_id" search="[('name','=','Mezzanine')]"/> | ||
2609 | 60 | </record> | ||
2610 | 61 | |||
2611 | 62 | <record id="product_product_mezzanine0" model="product.product"> | ||
2612 | 63 | <field eval="1" name="active"/> | ||
2613 | 64 | <field name="product_tmpl_id" ref="product_template_mezzanine"/> | ||
2614 | 65 | <field eval="[(6,0,[ref('product_variant_dimension_value_0'),ref('product_variant_dimension_value_2')])]" name="dimension_value_ids"/> | ||
2615 | 66 | </record> | ||
2616 | 67 | <record id="product_product_mezzanine1" model="product.product"> | ||
2617 | 68 | <field eval="1" name="active"/> | ||
2618 | 69 | <field name="product_tmpl_id" ref="product_template_mezzanine"/> | ||
2619 | 70 | <field eval="[(6,0,[ref('product_variant_dimension_value_0'),ref('product_variant_dimension_value_3')])]" name="dimension_value_ids"/> | ||
2620 | 71 | </record> | ||
2621 | 72 | <record id="product_product_mezzanine2" model="product.product"> | ||
2622 | 73 | <field eval="1" name="active"/> | ||
2623 | 74 | <field name="product_tmpl_id" ref="product_template_mezzanine"/> | ||
2624 | 75 | <field eval="[(6,0,[ref('product_variant_dimension_value_1'),ref('product_variant_dimension_value_2')])]" name="dimension_value_ids"/> | ||
2625 | 76 | </record> | ||
2626 | 77 | <record id="product_product_mezzanine3" model="product.product"> | ||
2627 | 78 | <field eval="1" name="active"/> | ||
2628 | 79 | <field name="product_tmpl_id" ref="product_template_mezzanine"/> | ||
2629 | 80 | <field eval="[(6,0,[ref('product_variant_dimension_value_1'),ref('product_variant_dimension_value_3')])]" name="dimension_value_ids"/> | ||
2630 | 81 | </record> | ||
2631 | 82 | --> | ||
2632 | 83 | </data> | ||
2633 | 84 | </openerp> | ||
2634 | 85 | 0 | ||
2635 | === added directory 'product_variant_simple' | |||
2636 | === added file 'product_variant_simple/__init__.py' | |||
2637 | --- product_variant_simple/__init__.py 1970-01-01 00:00:00 +0000 | |||
2638 | +++ product_variant_simple/__init__.py 2014-06-24 09:37:35 +0000 | |||
2639 | @@ -0,0 +1,3 @@ | |||
2640 | 1 | # -*- coding: utf-8 -*- | ||
2641 | 2 | |||
2642 | 3 | from . import product | ||
2643 | 0 | 4 | ||
2644 | === added file 'product_variant_simple/__openerp__.py' | |||
2645 | --- product_variant_simple/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
2646 | +++ product_variant_simple/__openerp__.py 2014-06-24 09:37:35 +0000 | |||
2647 | @@ -0,0 +1,47 @@ | |||
2648 | 1 | # -*- coding: utf-8 -*- | ||
2649 | 2 | ############################################################################## | ||
2650 | 3 | # | ||
2651 | 4 | # Author: Yannick Vaucher | ||
2652 | 5 | # Copyright 2013 Camptocamp SA | ||
2653 | 6 | # | ||
2654 | 7 | # This program is free software: you can redistribute it and/or modify | ||
2655 | 8 | # it under the terms of the GNU Affero General Public License as | ||
2656 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
2657 | 10 | # License, or (at your option) any later version. | ||
2658 | 11 | # | ||
2659 | 12 | # This program is distributed in the hope that it will be useful, | ||
2660 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2661 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2662 | 15 | # GNU Affero General Public License for more details. | ||
2663 | 16 | # | ||
2664 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
2665 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2666 | 19 | # | ||
2667 | 20 | ############################################################################## | ||
2668 | 21 | {'name' : 'Simple Product Variants', | ||
2669 | 22 | 'version' : '1.0', | ||
2670 | 23 | 'category': '', | ||
2671 | 24 | 'description': """ | ||
2672 | 25 | Simple Product Variants | ||
2673 | 26 | ======================= | ||
2674 | 27 | |||
2675 | 28 | A simple module for handling the product variants. | ||
2676 | 29 | It provides views for templates and for variants, | ||
2677 | 30 | so they can be created manually. It doesn't provide | ||
2678 | 31 | all the bells and whistles of the product_variant_multi | ||
2679 | 32 | module (generators wizards, ...). | ||
2680 | 33 | |||
2681 | 34 | """, | ||
2682 | 35 | 'author' : 'Camptocamp', | ||
2683 | 36 | 'maintainer': 'Camptocamp', | ||
2684 | 37 | 'website': 'http://www.camptocamp.com/', | ||
2685 | 38 | 'depends' : ['product', | ||
2686 | 39 | ], | ||
2687 | 40 | 'data': ['product_view.xml', | ||
2688 | 41 | 'security/security.xml', | ||
2689 | 42 | ], | ||
2690 | 43 | 'test': [], | ||
2691 | 44 | 'installable': True, | ||
2692 | 45 | 'auto_install': False, | ||
2693 | 46 | 'application': True, | ||
2694 | 47 | } | ||
2695 | 0 | 48 | ||
2696 | === added file 'product_variant_simple/product.py' | |||
2697 | --- product_variant_simple/product.py 1970-01-01 00:00:00 +0000 | |||
2698 | +++ product_variant_simple/product.py 2014-06-24 09:37:35 +0000 | |||
2699 | @@ -0,0 +1,32 @@ | |||
2700 | 1 | # -*- coding: utf-8 -*- | ||
2701 | 2 | ############################################################################## | ||
2702 | 3 | # | ||
2703 | 4 | # Author: Guewen Baconnier | ||
2704 | 5 | # Copyright 2013 Camptocamp SA | ||
2705 | 6 | # | ||
2706 | 7 | # This program is free software: you can redistribute it and/or modify | ||
2707 | 8 | # it under the terms of the GNU Affero General Public License as | ||
2708 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
2709 | 10 | # License, or (at your option) any later version. | ||
2710 | 11 | # | ||
2711 | 12 | # This program is distributed in the hope that it will be useful, | ||
2712 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2713 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2714 | 15 | # GNU Affero General Public License for more details. | ||
2715 | 16 | # | ||
2716 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
2717 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2718 | 19 | # | ||
2719 | 20 | ############################################################################## | ||
2720 | 21 | |||
2721 | 22 | from openerp.osv import orm, fields | ||
2722 | 23 | |||
2723 | 24 | |||
2724 | 25 | class ProductTemplate(orm.Model): | ||
2725 | 26 | _inherit = 'product.template' | ||
2726 | 27 | _columns = { | ||
2727 | 28 | 'variant_ids': fields.one2many( | ||
2728 | 29 | 'product.product', | ||
2729 | 30 | 'product_tmpl_id', | ||
2730 | 31 | string='Variants'), | ||
2731 | 32 | } | ||
2732 | 0 | 33 | ||
2733 | === added file 'product_variant_simple/product_view.xml' | |||
2734 | --- product_variant_simple/product_view.xml 1970-01-01 00:00:00 +0000 | |||
2735 | +++ product_variant_simple/product_view.xml 2014-06-24 09:37:35 +0000 | |||
2736 | @@ -0,0 +1,92 @@ | |||
2737 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
2738 | 2 | <openerp> | ||
2739 | 3 | <data> | ||
2740 | 4 | |||
2741 | 5 | <!-- Templates --> | ||
2742 | 6 | |||
2743 | 7 | <record id="product_template_search_view" model="ir.ui.view"> | ||
2744 | 8 | <field name="name">product.template.search</field> | ||
2745 | 9 | <field name="model">product.template</field> | ||
2746 | 10 | <field name="arch" type="xml"> | ||
2747 | 11 | <search string="Product Templates"> | ||
2748 | 12 | <field name="name" string="Product"/> | ||
2749 | 13 | <filter string="Services" icon="terp-accessories-archiver" domain="[('type','=','service')]"/> | ||
2750 | 14 | <filter string="Consumable" name="consumable" icon="terp-accessories-archiver" domain="[('type','=','consu')]" help="Consumable products"/> | ||
2751 | 15 | <field name="categ_id"/> | ||
2752 | 16 | <group expand='0' string='Group by...'> | ||
2753 | 17 | <filter string='Category' | ||
2754 | 18 | icon="terp-stock_symbol-selection" | ||
2755 | 19 | domain="[]" | ||
2756 | 20 | context="{'group_by': 'categ_id'}"/> | ||
2757 | 21 | <filter string='Type' | ||
2758 | 22 | icon="terp-stock_symbol-selection" | ||
2759 | 23 | domain="[]" | ||
2760 | 24 | context="{'group_by': 'type'}"/> | ||
2761 | 25 | </group> | ||
2762 | 26 | </search> | ||
2763 | 27 | </field> | ||
2764 | 28 | </record> | ||
2765 | 29 | |||
2766 | 30 | <record id="product_template" model="ir.actions.act_window"> | ||
2767 | 31 | <field name="name">Product Templates</field> | ||
2768 | 32 | <field name="res_model">product.template</field> | ||
2769 | 33 | <field name="view_type">form</field> | ||
2770 | 34 | <field name="domain">[]</field> | ||
2771 | 35 | <field name="view_mode">tree,form</field> | ||
2772 | 36 | <field name="search_view_id" ref="product_template_search_view"/> | ||
2773 | 37 | </record> | ||
2774 | 38 | |||
2775 | 39 | <menuitem action="product_template" id="menu_template" | ||
2776 | 40 | sequence="15" | ||
2777 | 41 | parent="base.menu_product" /> | ||
2778 | 42 | |||
2779 | 43 | <!-- Variants --> | ||
2780 | 44 | |||
2781 | 45 | <record id="product_variant_search_view" model="ir.ui.view"> | ||
2782 | 46 | <field name="name">product.variant.search</field> | ||
2783 | 47 | <field name="model">product.product</field> | ||
2784 | 48 | <field name="arch" type="xml"> | ||
2785 | 49 | <search string="Product Variants"> | ||
2786 | 50 | <field name="product_tmpl_id" string="Product"/> | ||
2787 | 51 | <field name="name" string="Variant" | ||
2788 | 52 | filter_domain="['|', '|', | ||
2789 | 53 | ('variants', 'ilike', self), | ||
2790 | 54 | ('default_code', 'ilike', self)]"/> | ||
2791 | 55 | <group expand='0' string='Group by...'> | ||
2792 | 56 | <filter string='Template' | ||
2793 | 57 | icon="terp-stock_symbol-selection" | ||
2794 | 58 | domain="[]" | ||
2795 | 59 | context="{'group_by': 'product_tmpl_id'}"/> | ||
2796 | 60 | </group> | ||
2797 | 61 | </search> | ||
2798 | 62 | </field> | ||
2799 | 63 | </record> | ||
2800 | 64 | |||
2801 | 65 | <record id="product_variant" model="ir.actions.act_window"> | ||
2802 | 66 | <field name="name">Product Variants</field> | ||
2803 | 67 | <field name="res_model">product.product</field> | ||
2804 | 68 | <field name="view_type">form</field> | ||
2805 | 69 | <field name="view_mode">tree,form</field> | ||
2806 | 70 | <field name="search_view_id" ref="product_variant_search_view"/> | ||
2807 | 71 | </record> | ||
2808 | 72 | |||
2809 | 73 | <record id="action_variant_tree" model="ir.actions.act_window.view"> | ||
2810 | 74 | <field name="sequence" eval="10" /> | ||
2811 | 75 | <field name="view_mode">tree</field> | ||
2812 | 76 | <field name="act_window_id" ref="product_variant" /> | ||
2813 | 77 | <field name="view_id" ref="product.product_variant_tree_view" /> | ||
2814 | 78 | </record> | ||
2815 | 79 | |||
2816 | 80 | <record id="action_variant_form" model="ir.actions.act_window.view"> | ||
2817 | 81 | <field name="sequence" eval="20" /> | ||
2818 | 82 | <field name="view_mode">form</field> | ||
2819 | 83 | <field name="act_window_id" ref="product_variant" /> | ||
2820 | 84 | <field name="view_id" ref="product.product_variant_form_view" /> | ||
2821 | 85 | </record> | ||
2822 | 86 | |||
2823 | 87 | <menuitem action="product_variant" id="menu_variant" | ||
2824 | 88 | sequence="20" | ||
2825 | 89 | parent="base.menu_product" /> | ||
2826 | 90 | |||
2827 | 91 | </data> | ||
2828 | 92 | </openerp> | ||
2829 | 0 | 93 | ||
2830 | === added directory 'product_variant_simple/security' | |||
2831 | === added file 'product_variant_simple/security/security.xml' | |||
2832 | --- product_variant_simple/security/security.xml 1970-01-01 00:00:00 +0000 | |||
2833 | +++ product_variant_simple/security/security.xml 2014-06-24 09:37:35 +0000 | |||
2834 | @@ -0,0 +1,13 @@ | |||
2835 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
2836 | 2 | <openerp> | ||
2837 | 3 | <data noupdate="1"> | ||
2838 | 4 | |||
2839 | 5 | <!-- Activate the Product Variant group on the Sales Manager --> | ||
2840 | 6 | <record model="res.groups" id="base.group_sale_manager"> | ||
2841 | 7 | <field name="implied_ids" eval="[(4, ref('product.group_product_variant'))]"/> | ||
2842 | 8 | </record> | ||
2843 | 9 | |||
2844 | 10 | </data> | ||
2845 | 11 | </openerp> | ||
2846 | 12 | |||
2847 | 13 | |||
2848 | 0 | 14 | ||
2849 | === added directory 'sale_product_display' | |||
2850 | === added file 'sale_product_display/__init__.py' | |||
2851 | --- sale_product_display/__init__.py 1970-01-01 00:00:00 +0000 | |||
2852 | +++ sale_product_display/__init__.py 2014-06-24 09:37:35 +0000 | |||
2853 | @@ -0,0 +1,23 @@ | |||
2854 | 1 | # -*- coding: utf-8 -*- | ||
2855 | 2 | ############################################################################### | ||
2856 | 3 | # | ||
2857 | 4 | # Module for OpenERP | ||
2858 | 5 | # Copyright (C) 2013 Akretion (http://www.akretion.com). | ||
2859 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
2860 | 7 | # | ||
2861 | 8 | # This program is free software: you can redistribute it and/or modify | ||
2862 | 9 | # it under the terms of the GNU Affero General Public License as | ||
2863 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
2864 | 11 | # License, or (at your option) any later version. | ||
2865 | 12 | # | ||
2866 | 13 | # This program is distributed in the hope that it will be useful, | ||
2867 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2868 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2869 | 16 | # GNU Affero General Public License for more details. | ||
2870 | 17 | # | ||
2871 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
2872 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2873 | 20 | # | ||
2874 | 21 | ############################################################################### | ||
2875 | 22 | |||
2876 | 23 | import sale | ||
2877 | 0 | 24 | ||
2878 | === added file 'sale_product_display/__openerp__.py' | |||
2879 | --- sale_product_display/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
2880 | +++ sale_product_display/__openerp__.py 2014-06-24 09:37:35 +0000 | |||
2881 | @@ -0,0 +1,40 @@ | |||
2882 | 1 | # -*- coding: utf-8 -*- | ||
2883 | 2 | ############################################################################## | ||
2884 | 3 | # | ||
2885 | 4 | # Author: Chafique Delli | ||
2886 | 5 | # Copyright 2013 Akretion | ||
2887 | 6 | # | ||
2888 | 7 | # This program is free software: you can redistribute it and/or modify | ||
2889 | 8 | # it under the terms of the GNU Affero General Public License as | ||
2890 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
2891 | 10 | # License, or (at your option) any later version. | ||
2892 | 11 | # | ||
2893 | 12 | # This program is distributed in the hope that it will be useful, | ||
2894 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2895 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2896 | 15 | # GNU Affero General Public License for more details. | ||
2897 | 16 | # | ||
2898 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
2899 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2900 | 19 | # | ||
2901 | 20 | ############################################################################## | ||
2902 | 21 | {'name' : 'Sale Product Display', | ||
2903 | 22 | 'version' : '1.0', | ||
2904 | 23 | "author": "Akretion", | ||
2905 | 24 | 'category': 'Sales Management', | ||
2906 | 25 | 'description': """ | ||
2907 | 26 | Sale Product Display | ||
2908 | 27 | ==================== | ||
2909 | 28 | |||
2910 | 29 | A simple module for preventing validation of a command that contains a product display. | ||
2911 | 30 | |||
2912 | 31 | """, | ||
2913 | 32 | 'author' : 'Akretion', | ||
2914 | 33 | 'maintainer': 'Akretion', | ||
2915 | 34 | 'website': 'http://www.akretion.com/', | ||
2916 | 35 | 'depends' : [ | ||
2917 | 36 | 'sale', | ||
2918 | 37 | 'product_display' | ||
2919 | 38 | ], | ||
2920 | 39 | 'auto_install': True, | ||
2921 | 40 | } | ||
2922 | 0 | 41 | ||
2923 | === added file 'sale_product_display/sale.py' | |||
2924 | --- sale_product_display/sale.py 1970-01-01 00:00:00 +0000 | |||
2925 | +++ sale_product_display/sale.py 2014-06-24 09:37:35 +0000 | |||
2926 | @@ -0,0 +1,39 @@ | |||
2927 | 1 | # -*- coding: utf-8 -*- | ||
2928 | 2 | ############################################################################### | ||
2929 | 3 | # | ||
2930 | 4 | # Module for OpenERP | ||
2931 | 5 | # Copyright (C) 2013 Akretion (http://www.akretion.com). | ||
2932 | 6 | # @author Chafique Delli <chafique.delli@akretion.com> | ||
2933 | 7 | # | ||
2934 | 8 | # This program is free software: you can redistribute it and/or modify | ||
2935 | 9 | # it under the terms of the GNU Affero General Public License as | ||
2936 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
2937 | 11 | # License, or (at your option) any later version. | ||
2938 | 12 | # | ||
2939 | 13 | # This program is distributed in the hope that it will be useful, | ||
2940 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2941 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2942 | 16 | # GNU Affero General Public License for more details. | ||
2943 | 17 | # | ||
2944 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
2945 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2946 | 20 | # | ||
2947 | 21 | ############################################################################### | ||
2948 | 22 | |||
2949 | 23 | from openerp.osv import orm, osv | ||
2950 | 24 | from openerp.tools.translate import _ | ||
2951 | 25 | |||
2952 | 26 | |||
2953 | 27 | class SaleOrderLine(orm.Model): | ||
2954 | 28 | _inherit = 'sale.order.line' | ||
2955 | 29 | |||
2956 | 30 | |||
2957 | 31 | def _check_product_display(self, cr, uid, ids, context=None): | ||
2958 | 32 | for record in self.browse(cr, uid, ids, context=context): | ||
2959 | 33 | if record.product_id.is_display: | ||
2960 | 34 | raise osv.except_osv(_('Error'), _('You cannot validate the order with product display %s.')% (record.product_id.name)) | ||
2961 | 35 | return True | ||
2962 | 36 | |||
2963 | 37 | _constraints = [ | ||
2964 | 38 | (_check_product_display, 'You cannot validate an order with a product display.', | ||
2965 | 39 | [])] |
Hello,
The management of the project has moved to Github: https:/ /github. com/OCA/ product- variant
Please migrate your merge proposal to Github. You may want to check https:/ /github. com/OCA/ maintainers- tools/wiki/ How-to- move-a- Merge-Proposal- to-GitHub for an explanation on how to proceed.
Thanks for contributing to the project