Merge lp:~unifield-team/unifield-server/us-1492 into lp:unifield-server

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
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+303573@code.launchpad.net
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 </data>
6 </field>
7 </record>
8-
9+
10+ <delete id="action_new_catalogue_supplier" model="ir.actions.act_window" />
11+ <record id="action_create_new_catalogue" model="ir.actions.server">
12+ <field name="name">New Catalogue</field>
13+ <field name="model_id" ref="model_supplier_catalogue"/>
14+ <field name="state">code</field>
15+ <field name="code">action = obj.open_new_catalogue_form(context=context)</field>
16+ </record>
17+
18 <!-- Action to create a new catalogue for this supplier -->
19- <act_window
20- name="New catalogue"
21- res_model="supplier.catalogue"
22- src_model="res.partner"
23- view_mode="form,tree"
24- view_type="form"
25- key2="client_action_multi"
26- domain="[('partner_id', '=', active_id)]"
27- context="{'partner_id': active_id}"
28- id="action_new_catalogue_supplier" />
29-
30+ <record id="action_new_catalogue_supplier2" model="ir.values">
31+ <field name="key2">client_action_multi</field>
32+ <field name="model">res.partner</field>
33+ <field name="name">New catalogue</field>
34+ <field eval="'ir.actions.server,%d'%action_create_new_catalogue" name="value"/>
35+ <field name="context">{'partner_id': active_id}</field>
36+ <field name="sequence" eval="1" />
37+ <field eval="True" name="object"/>
38+ </record>
39+
40 <!-- Choose catalogue from supplier (osv_memory) form view -->
41 <record id="from_supplier_choose_catalogue_form_view" model="ir.ui.view">
42 <field name="name">from.supplier.choose.catalogue.form.view</field>
43
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
49 return False
50
51+ def open_new_catalogue_form(self, cr, uid, ids, context=None):
52+ if context is None:
53+ context = {}
54+ context['partner_id'] = ids[0]
55+ partner_obj = self.pool.get('res.partner')
56+ if partner_obj.search(cr, uid, [('id', '=', ids[0]), ('partner_type', '=', 'esc')], context=context):
57+ user = self.pool.get('res.users').browse(cr, uid, uid,context=context)
58+ level = user and user.company_id and user.company_id.instance_id and user.company_id.instance_id.level or False
59+ if level != 'section':
60+ raise osv.except_osv(
61+ _('Error'),
62+ 'For an ESC Supplier you must create the catalogue on a HQ instance.'
63+ )
64+ elif self.search(cr, uid, [('active', '=', True), ('partner_id', '=', ids[0])]):
65+ raise osv.except_osv(
66+ _('Error'),
67+ _('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+ )
69+
70+ return {
71+ 'res_model': 'supplier.catalogue',
72+ 'view_type': 'form',
73+ 'view_mode': 'form,tree',
74+ 'type': 'ir.actions.act_window',
75+ 'context': context,
76+ 'domain': [('partner_id', '=', ids[0])],
77+ }
78 def _update_other_catalogue(self, cr, uid, cat_id, period_from, currency_id, partner_id, period_to=False, context=None):
79 '''
80 Check if other catalogues with the same partner/currency exist and are defined in the period of the
81@@ -83,21 +110,6 @@
82 order='period_from asc',
83 limit=1,
84 context=context)
85- if period_to:
86- to_ids = self.search(cr, uid, [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from),
87- ('period_from', '<', period_to),
88- ('currency_id', '=', currency_id),
89- ('partner_id', '=', partner_id)],
90- order='period_from asc',
91- limit=1,
92- context=context)
93- else:
94- to_ids = self.search(cr, uid, [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from),
95- ('currency_id', '=', currency_id),
96- ('partner_id', '=', partner_id)],
97- order='period_from asc',
98- limit=1,
99- context=context)
100
101 # If overrided catalogues exist, display an error message
102 if equal_ids:
103@@ -111,6 +123,30 @@
104 raise osv.except_osv(_('Error'), _('This catalogue has the same \'From\' date than the following catalogue : %s (\'From\' : %s - \'To\' : %s) - ' \
105 'Please change the \'From\' date of this new catalogue or delete the other catalogue.') % (over_cat.name, over_cat_from, over_cat_to))
106
107+ elif cat and cat.is_esc:
108+ raise osv.except_osv(
109+ _('Error'),
110+ _('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+ )
112+
113+ if period_to:
114+ to_ids = self.search(cr, uid,
115+ [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from),
116+ ('period_from', '<', period_to),
117+ ('currency_id', '=', currency_id),
118+ ('partner_id', '=', partner_id)],
119+ order='period_from asc',
120+ limit=1,
121+ context=context)
122+ else:
123+ to_ids = self.search(cr, uid,
124+ [('id', 'not in', context.get('cat_ids', [])), ('period_from', '>', period_from),
125+ ('currency_id', '=', currency_id),
126+ ('partner_id', '=', partner_id)],
127+ order='period_from asc',
128+ limit=1,
129+ context=context)
130+
131 # If overrided catalogues exist, display an error message
132 if to_ids:
133 over_cat = self.browse(cr, uid, to_ids[0], context=context)
134@@ -159,6 +195,12 @@
135 catalogue = self.browse(cr, uid, [res], context=context)[0]
136 if not catalogue.partner_id.active:
137 self.write(cr, uid, [res], {'active': False}, context=context)
138+ elif not context.get('sync_update_execution') and vals.get('active') and catalogue.partner_id.partner_type == 'esc':
139+ if self.search(cr, uid, [('partner_id', '=', catalogue.partner_id.id), ('active', '=', True)], count=True, context=context) > 1:
140+ raise osv.except_osv(
141+ _('Error'),
142+ _('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+ )
144
145 return res
146
147@@ -255,6 +297,33 @@
148
149 return True
150
151+ def check_inactive_catalogues(self, cr, uid, ids, partner_id, context=None):
152+ '''
153+ Check if there are an inactive catalogue for this supplier. If yes, display a warning messagse
154+ '''
155+ res = {}
156+
157+ if not ids:
158+ ids = []
159+
160+ if partner_id and self.pool.get('res.partner').read(cr, uid, partner_id, ['partner_type'], context=context)['partner_type'] == 'esc':
161+ equal_ids = self.search(cr, uid, [
162+ ('id', 'not in', ids),
163+ ('active', '=', False),
164+ ('partner_id', '=', partner_id),
165+ ], order='period_from asc', limit=1, context=context)
166+ if equal_ids:
167+ res.update({
168+ 'warning': {
169+ 'title': _('Warning'),
170+ '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+ },
172+ })
173+
174+
175+
176+ return res
177+
178 def button_draft(self, cr, uid, ids, context=None):
179 '''
180 Reset to draft the catalogue
181@@ -375,7 +444,7 @@
182 _columns = {
183 'name': fields.char(size=64, string='Name', required=True),
184 'partner_id': fields.many2one('res.partner', string='Partner', required=True,
185- domain=[('supplier', '=', True)]),
186+ domain=[('supplier', '=', True)], select=1),
187 'period_from': fields.date(string='From',
188 help='Starting date of the catalogue.'),
189 'period_to': fields.date(string='To',
190
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 <field name="type">form</field>
196 <field name="arch" type="xml">
197 <form string="Supplier catalogue">
198- <field name="name" colspan="4" />
199+ <field name="name" colspan="4" on_change="check_inactive_catalogues(partner_id)" />
200 <field name="period_from" attrs="{'required': [('is_esc', '=', False)], 'invisible': [('is_esc', '=', True)]}" />
201 <field name="period_to" attrs="{'invisible': [('is_esc', '=', True)]}" />
202 <field name="currency_id" domain="[('partner_currency', '=', partner_id)]" />

Subscribers

People subscribed via source and target branches

to all changes: