Merge lp:~unifield-team/unifield-server/us-1492 into lp:unifield-server
- us-1492
- Merge into trunk
Proposed by
jftempo
Status: | Merged |
---|---|
Merged at revision: | 3938 |
Proposed branch: | lp:~unifield-team/unifield-server/us-1492 |
Merge into: | lp:unifield-server |
Diff against target: |
202 lines (+105/-29) 3 files modified
bin/addons/supplier_catalogue/partner_view.xml (+19/-12) bin/addons/supplier_catalogue/supplier_catalogue.py (+85/-16) bin/addons/supplier_catalogue/supplier_catalogue_view.xml (+1/-1) |
To merge this branch: | bzr merge lp:~unifield-team/unifield-server/us-1492 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email: mp+303573@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/addons/supplier_catalogue/partner_view.xml' | |||
2 | --- bin/addons/supplier_catalogue/partner_view.xml 2013-02-13 06:50:09 +0000 | |||
3 | +++ bin/addons/supplier_catalogue/partner_view.xml 2016-08-22 14:53:53 +0000 | |||
4 | @@ -28,19 +28,26 @@ | |||
5 | 28 | </data> | 28 | </data> |
6 | 29 | </field> | 29 | </field> |
7 | 30 | </record> | 30 | </record> |
9 | 31 | 31 | ||
10 | 32 | <delete id="action_new_catalogue_supplier" model="ir.actions.act_window" /> | ||
11 | 33 | <record id="action_create_new_catalogue" model="ir.actions.server"> | ||
12 | 34 | <field name="name">New Catalogue</field> | ||
13 | 35 | <field name="model_id" ref="model_supplier_catalogue"/> | ||
14 | 36 | <field name="state">code</field> | ||
15 | 37 | <field name="code">action = obj.open_new_catalogue_form(context=context)</field> | ||
16 | 38 | </record> | ||
17 | 39 | |||
18 | 32 | <!-- Action to create a new catalogue for this supplier --> | 40 | <!-- Action to create a new catalogue for this supplier --> |
30 | 33 | <act_window | 41 | <record id="action_new_catalogue_supplier2" model="ir.values"> |
31 | 34 | name="New catalogue" | 42 | <field name="key2">client_action_multi</field> |
32 | 35 | res_model="supplier.catalogue" | 43 | <field name="model">res.partner</field> |
33 | 36 | src_model="res.partner" | 44 | <field name="name">New catalogue</field> |
34 | 37 | view_mode="form,tree" | 45 | <field eval="'ir.actions.server,%d'%action_create_new_catalogue" name="value"/> |
35 | 38 | view_type="form" | 46 | <field name="context">{'partner_id': active_id}</field> |
36 | 39 | key2="client_action_multi" | 47 | <field name="sequence" eval="1" /> |
37 | 40 | domain="[('partner_id', '=', active_id)]" | 48 | <field eval="True" name="object"/> |
38 | 41 | context="{'partner_id': active_id}" | 49 | </record> |
39 | 42 | id="action_new_catalogue_supplier" /> | 50 | |
29 | 43 | |||
40 | 44 | <!-- Choose catalogue from supplier (osv_memory) form view --> | 51 | <!-- Choose catalogue from supplier (osv_memory) form view --> |
41 | 45 | <record id="from_supplier_choose_catalogue_form_view" model="ir.ui.view"> | 52 | <record id="from_supplier_choose_catalogue_form_view" model="ir.ui.view"> |
42 | 46 | <field name="name">from.supplier.choose.catalogue.form.view</field> | 53 | <field name="name">from.supplier.choose.catalogue.form.view</field> |
43 | 47 | 54 | ||
44 | === modified file 'bin/addons/supplier_catalogue/supplier_catalogue.py' | |||
45 | --- bin/addons/supplier_catalogue/supplier_catalogue.py 2016-04-29 07:39:24 +0000 | |||
46 | +++ bin/addons/supplier_catalogue/supplier_catalogue.py 2016-08-22 14:53:53 +0000 | |||
47 | @@ -58,6 +58,33 @@ | |||
48 | 58 | 58 | ||
49 | 59 | return False | 59 | return False |
50 | 60 | 60 | ||
51 | 61 | def open_new_catalogue_form(self, cr, uid, ids, context=None): | ||
52 | 62 | if context is None: | ||
53 | 63 | context = {} | ||
54 | 64 | context['partner_id'] = ids[0] | ||
55 | 65 | partner_obj = self.pool.get('res.partner') | ||
56 | 66 | if partner_obj.search(cr, uid, [('id', '=', ids[0]), ('partner_type', '=', 'esc')], context=context): | ||
57 | 67 | user = self.pool.get('res.users').browse(cr, uid, uid,context=context) | ||
58 | 68 | level = user and user.company_id and user.company_id.instance_id and user.company_id.instance_id.level or False | ||
59 | 69 | if level != 'section': | ||
60 | 70 | raise osv.except_osv( | ||
61 | 71 | _('Error'), | ||
62 | 72 | 'For an ESC Supplier you must create the catalogue on a HQ instance.' | ||
63 | 73 | ) | ||
64 | 74 | elif self.search(cr, uid, [('active', '=', True), ('partner_id', '=', ids[0])]): | ||
65 | 75 | raise osv.except_osv( | ||
66 | 76 | _('Error'), | ||
67 | 77 | _('Warning! There is already another active catalogue for this Supplier! This could have implications on the synching of catalogue to instances below, please check.'), | ||
68 | 78 | ) | ||
69 | 79 | |||
70 | 80 | return { | ||
71 | 81 | 'res_model': 'supplier.catalogue', | ||
72 | 82 | 'view_type': 'form', | ||
73 | 83 | 'view_mode': 'form,tree', | ||
74 | 84 | 'type': 'ir.actions.act_window', | ||
75 | 85 | 'context': context, | ||
76 | 86 | 'domain': [('partner_id', '=', ids[0])], | ||
77 | 87 | } | ||
78 | 61 | def _update_other_catalogue(self, cr, uid, cat_id, period_from, currency_id, partner_id, period_to=False, context=None): | 88 | def _update_other_catalogue(self, cr, uid, cat_id, period_from, currency_id, partner_id, period_to=False, context=None): |
79 | 62 | ''' | 89 | ''' |
80 | 63 | Check if other catalogues with the same partner/currency exist and are defined in the period of the | 90 | Check if other catalogues with the same partner/currency exist and are defined in the period of the |
81 | @@ -83,21 +110,6 @@ | |||
82 | 83 | order='period_from asc', | 110 | order='period_from asc', |
83 | 84 | limit=1, | 111 | limit=1, |
84 | 85 | context=context) | 112 | context=context) |
85 | 86 | if period_to: | ||
86 | 87 | to_ids = self.search(cr, uid, [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from), | ||
87 | 88 | ('period_from', '<', period_to), | ||
88 | 89 | ('currency_id', '=', currency_id), | ||
89 | 90 | ('partner_id', '=', partner_id)], | ||
90 | 91 | order='period_from asc', | ||
91 | 92 | limit=1, | ||
92 | 93 | context=context) | ||
93 | 94 | else: | ||
94 | 95 | to_ids = self.search(cr, uid, [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from), | ||
95 | 96 | ('currency_id', '=', currency_id), | ||
96 | 97 | ('partner_id', '=', partner_id)], | ||
97 | 98 | order='period_from asc', | ||
98 | 99 | limit=1, | ||
99 | 100 | context=context) | ||
100 | 101 | 113 | ||
101 | 102 | # If overrided catalogues exist, display an error message | 114 | # If overrided catalogues exist, display an error message |
102 | 103 | if equal_ids: | 115 | if equal_ids: |
103 | @@ -111,6 +123,30 @@ | |||
104 | 111 | raise osv.except_osv(_('Error'), _('This catalogue has the same \'From\' date than the following catalogue : %s (\'From\' : %s - \'To\' : %s) - ' \ | 123 | raise osv.except_osv(_('Error'), _('This catalogue has the same \'From\' date than the following catalogue : %s (\'From\' : %s - \'To\' : %s) - ' \ |
105 | 112 | 'Please change the \'From\' date of this new catalogue or delete the other catalogue.') % (over_cat.name, over_cat_from, over_cat_to)) | 124 | 'Please change the \'From\' date of this new catalogue or delete the other catalogue.') % (over_cat.name, over_cat_from, over_cat_to)) |
106 | 113 | 125 | ||
107 | 126 | elif cat and cat.is_esc: | ||
108 | 127 | raise osv.except_osv( | ||
109 | 128 | _('Error'), | ||
110 | 129 | _('Warning! There is already another active catalogue for this Supplier! This could have implications on the synching of catalogue to instances below, please check.'), | ||
111 | 130 | ) | ||
112 | 131 | |||
113 | 132 | if period_to: | ||
114 | 133 | to_ids = self.search(cr, uid, | ||
115 | 134 | [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from), | ||
116 | 135 | ('period_from', '<', period_to), | ||
117 | 136 | ('currency_id', '=', currency_id), | ||
118 | 137 | ('partner_id', '=', partner_id)], | ||
119 | 138 | order='period_from asc', | ||
120 | 139 | limit=1, | ||
121 | 140 | context=context) | ||
122 | 141 | else: | ||
123 | 142 | to_ids = self.search(cr, uid, | ||
124 | 143 | [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from), | ||
125 | 144 | ('currency_id', '=', currency_id), | ||
126 | 145 | ('partner_id', '=', partner_id)], | ||
127 | 146 | order='period_from asc', | ||
128 | 147 | limit=1, | ||
129 | 148 | context=context) | ||
130 | 149 | |||
131 | 114 | # If overrided catalogues exist, display an error message | 150 | # If overrided catalogues exist, display an error message |
132 | 115 | if to_ids: | 151 | if to_ids: |
133 | 116 | over_cat = self.browse(cr, uid, to_ids[0], context=context) | 152 | over_cat = self.browse(cr, uid, to_ids[0], context=context) |
134 | @@ -159,6 +195,12 @@ | |||
135 | 159 | catalogue = self.browse(cr, uid, [res], context=context)[0] | 195 | catalogue = self.browse(cr, uid, [res], context=context)[0] |
136 | 160 | if not catalogue.partner_id.active: | 196 | if not catalogue.partner_id.active: |
137 | 161 | self.write(cr, uid, [res], {'active': False}, context=context) | 197 | self.write(cr, uid, [res], {'active': False}, context=context) |
138 | 198 | elif not context.get('sync_update_execution') and vals.get('active') and catalogue.partner_id.partner_type == 'esc': | ||
139 | 199 | if self.search(cr, uid, [('partner_id', '=', catalogue.partner_id.id), ('active', '=', True)], count=True, context=context) > 1: | ||
140 | 200 | raise osv.except_osv( | ||
141 | 201 | _('Error'), | ||
142 | 202 | _('Warning! There is already another active catalogue for this Supplier! This could have implications on the synching of catalogue to instances below, please check.'), | ||
143 | 203 | ) | ||
144 | 162 | 204 | ||
145 | 163 | return res | 205 | return res |
146 | 164 | 206 | ||
147 | @@ -255,6 +297,33 @@ | |||
148 | 255 | 297 | ||
149 | 256 | return True | 298 | return True |
150 | 257 | 299 | ||
151 | 300 | def check_inactive_catalogues(self, cr, uid, ids, partner_id, context=None): | ||
152 | 301 | ''' | ||
153 | 302 | Check if there are an inactive catalogue for this supplier. If yes, display a warning messagse | ||
154 | 303 | ''' | ||
155 | 304 | res = {} | ||
156 | 305 | |||
157 | 306 | if not ids: | ||
158 | 307 | ids = [] | ||
159 | 308 | |||
160 | 309 | if partner_id and self.pool.get('res.partner').read(cr, uid, partner_id, ['partner_type'], context=context)['partner_type'] == 'esc': | ||
161 | 310 | equal_ids = self.search(cr, uid, [ | ||
162 | 311 | ('id', 'not in', ids), | ||
163 | 312 | ('active', '=', False), | ||
164 | 313 | ('partner_id', '=', partner_id), | ||
165 | 314 | ], order='period_from asc', limit=1, context=context) | ||
166 | 315 | if equal_ids: | ||
167 | 316 | res.update({ | ||
168 | 317 | 'warning': { | ||
169 | 318 | 'title': _('Warning'), | ||
170 | 319 | 'message': _('Warning! There is already another inactive catalogue for this Supplier! This could have implications on the synching of catalogue to instances below, please check'), | ||
171 | 320 | }, | ||
172 | 321 | }) | ||
173 | 322 | |||
174 | 323 | |||
175 | 324 | |||
176 | 325 | return res | ||
177 | 326 | |||
178 | 258 | def button_draft(self, cr, uid, ids, context=None): | 327 | def button_draft(self, cr, uid, ids, context=None): |
179 | 259 | ''' | 328 | ''' |
180 | 260 | Reset to draft the catalogue | 329 | Reset to draft the catalogue |
181 | @@ -375,7 +444,7 @@ | |||
182 | 375 | _columns = { | 444 | _columns = { |
183 | 376 | 'name': fields.char(size=64, string='Name', required=True), | 445 | 'name': fields.char(size=64, string='Name', required=True), |
184 | 377 | 'partner_id': fields.many2one('res.partner', string='Partner', required=True, | 446 | 'partner_id': fields.many2one('res.partner', string='Partner', required=True, |
186 | 378 | domain=[('supplier', '=', True)]), | 447 | domain=[('supplier', '=', True)], select=1), |
187 | 379 | 'period_from': fields.date(string='From', | 448 | 'period_from': fields.date(string='From', |
188 | 380 | help='Starting date of the catalogue.'), | 449 | help='Starting date of the catalogue.'), |
189 | 381 | 'period_to': fields.date(string='To', | 450 | 'period_to': fields.date(string='To', |
190 | 382 | 451 | ||
191 | === modified file 'bin/addons/supplier_catalogue/supplier_catalogue_view.xml' | |||
192 | --- bin/addons/supplier_catalogue/supplier_catalogue_view.xml 2016-03-31 08:47:35 +0000 | |||
193 | +++ bin/addons/supplier_catalogue/supplier_catalogue_view.xml 2016-08-22 14:53:53 +0000 | |||
194 | @@ -31,7 +31,7 @@ | |||
195 | 31 | <field name="type">form</field> | 31 | <field name="type">form</field> |
196 | 32 | <field name="arch" type="xml"> | 32 | <field name="arch" type="xml"> |
197 | 33 | <form string="Supplier catalogue"> | 33 | <form string="Supplier catalogue"> |
199 | 34 | <field name="name" colspan="4" /> | 34 | <field name="name" colspan="4" on_change="check_inactive_catalogues(partner_id)" /> |
200 | 35 | <field name="period_from" attrs="{'required': [('is_esc', '=', False)], 'invisible': [('is_esc', '=', True)]}" /> | 35 | <field name="period_from" attrs="{'required': [('is_esc', '=', False)], 'invisible': [('is_esc', '=', True)]}" /> |
201 | 36 | <field name="period_to" attrs="{'invisible': [('is_esc', '=', True)]}" /> | 36 | <field name="period_to" attrs="{'invisible': [('is_esc', '=', True)]}" /> |
202 | 37 | <field name="currency_id" domain="[('partner_currency', '=', partner_id)]" /> | 37 | <field name="currency_id" domain="[('partner_currency', '=', partner_id)]" /> |