- Timestamp:
- 29 Dec 2014, 23:05:40 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py
r12333 r12337 88 88 view.redirect(view.url(view.context)) 89 89 return 90 91 def isCustomer(principal): 92 return getattr(principal, 'user_type', None) == 'customer' 90 93 91 94 … … 1093 1096 1094 1097 1095 class Contracts ManageFormPage(IkobaEditFormPage):1096 """ Page to manage the customer contracts1097 1098 This manageform page is for both customers and officers.1098 class ContractsFormPage(IkobaEditFormPage): 1099 """ Page to display, edit or manage customer contracts 1100 1101 This form page is for both customers and officers. 1099 1102 """ 1100 1103 grok.context(IContractsContainer) … … 1106 1109 1107 1110 @property 1108 def manage_contracts_allowed(self): 1111 def edit_contracts_allowed(self): 1112 right_customer_state = self.context.customer.state in getUtility( 1113 ICustomersUtils).CONMANAGE_CUSTOMER_STATES 1114 if isCustomer(self.request.principal) and not right_customer_state: 1115 return False 1109 1116 return checkPermission('waeup.editContracts', self.context) 1110 1117 1111 def unremovable(self, contract): 1112 usertype = getattr(self.request.principal, 'user_type', None) 1113 if not usertype: 1114 return False 1115 if not self.manage_contracts_allowed: 1116 return True 1117 return (self.request.principal.user_type == 'customer' and \ 1118 contract.state in (APPROVED, REJECTED, EXPIRED)) 1118 def remove_contract_allowed(self, contract): 1119 if isCustomer(self.request.principal): 1120 right_customer_state = self.context.customer.state in getUtility( 1121 ICustomersUtils).CONMANAGE_CUSTOMER_STATES 1122 if not right_customer_state: 1123 return False 1124 if contract.state in (APPROVED, REJECTED, EXPIRED): 1125 return False 1126 return checkPermission('waeup.editContracts', self.context) 1119 1127 1120 1128 @property … … 1143 1151 # Customers are not allowed to remove used contracts 1144 1152 contract = self.context.get(id, None) 1145 if contract is not None and not self.unremovable(contract):1153 if contract is not None and self.remove_contract_allowed(contract): 1146 1154 del self.context[id] 1147 1155 deleted.append(id) … … 1155 1163 1156 1164 1157 class ContractAdd FormPage(IkobaAddFormPage):1165 class ContractAddPage(IkobaAddFormPage): 1158 1166 """ Page to add an contract 1167 1168 This page is for both customers and officers. 1159 1169 """ 1160 1170 grok.context(IContractsContainer) 1161 1171 grok.name('addcontract') 1162 grok.template('contractadd form')1172 grok.template('contractaddpage') 1163 1173 grok.require('waeup.editContracts') 1164 1174 label = _('Add contract') … … 1167 1177 form_fields = grok.AutoFields(IContract).omit( 1168 1178 'product_object', 'contract_id', 'product_options') 1179 1180 @property 1181 def edit_contracts_allowed(self): 1182 right_customer_state = self.context.customer.state in getUtility( 1183 ICustomersUtils).CONMANAGE_CUSTOMER_STATES 1184 if isCustomer(self.request.principal) and not right_customer_state: 1185 return False 1186 return True 1187 1188 def update(self): 1189 if not self.edit_contracts_allowed: 1190 emit_lock_message(self) 1191 return 1192 return super(ContractAddPage, self).update() 1169 1193 1170 1194 @property … … 1187 1211 self.context.writeLogMessage( 1188 1212 self,'added: %s %s' % (contype, contract.contract_id)) 1189 self.redirect(self.url( self.context))1213 self.redirect(self.url(contract, 'selectproduct')) 1190 1214 return 1191 1215 … … 1193 1217 def cancel(self, **data): 1194 1218 self.redirect(self.url(self.context)) 1219 1220 1221 class ContractSelectProductPage(IkobaAddFormPage): 1222 """ Page to select a contract product 1223 1224 This page is for both customers and officers. 1225 """ 1226 grok.context(IContract) 1227 grok.name('selectproduct') 1228 grok.require('waeup.editContracts') 1229 label = _('Select product') 1230 pnav = 4 1231 1232 form_fields = grok.AutoFields(IContract).select('product_object') 1233 1234 def update(self): 1235 if not self.context.is_editable and self.context.product_options == []: 1236 emit_lock_message(self) 1237 return 1238 return super(ContractSelectProductPage, self).update() 1239 1240 @action(_('Save and proceed'), style='primary') 1241 def save(self, **data): 1242 msave(self, **data) 1243 isCustomer = getattr( 1244 self.request.principal, 'user_type', None) == 'customer' 1245 if isCustomer: 1246 self.redirect(self.url(self.context, 'edit')) 1247 else: 1248 self.redirect(self.url(self.context, 'manage')) 1249 return 1195 1250 1196 1251 … … 1227 1282 deletion_warning = _('Are you sure?') 1228 1283 1284 def update(self): 1285 if not self.context.is_editable: 1286 emit_lock_message(self) 1287 return 1288 return super(ContractManageFormPage, self).update() 1289 1229 1290 @property 1230 1291 def form_fields(self): … … 1243 1304 1244 1305 class ContractEditFormPage(ContractManageFormPage): 1245 """ Page to edit a contract 1306 """ Page to edit a contract by customer only 1246 1307 """ 1247 1308 grok.name('edit') … … 1251 1312 def form_fields(self): 1252 1313 return grok.AutoFields(self.context.edit_form_fields_interface).omit( 1253 'contract_id') 1254 1255 def update(self): 1256 if not self.context.is_editable_by_customer: 1257 emit_lock_message(self) 1258 return 1259 return super(ContractEditFormPage, self).update() 1314 'contract_id', 'product_object') 1260 1315 1261 1316 @action(_('Save'), style='primary') … … 1342 1397 def render(self): 1343 1398 portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE 1344 Id = translate(_('Id'), 'waeup.ikoba', target_language=portal_language)1399 #Id = translate(_('Id'), 'waeup.ikoba', target_language=portal_language) 1345 1400 Title = translate(_('Title'), 'waeup.ikoba', target_language=portal_language) 1346 1401 Type = translate(_('Type'), 'waeup.ikoba', target_language=portal_language) … … 1353 1408 tabledata.append(sorted( 1354 1409 [value for value in self.context.values()])) 1355 tableheader.append([(Id, 'contract_id', 2), 1410 tableheader.append([ 1411 #(Id, 'contract_id', 2), 1356 1412 (Title, 'title', 6), 1357 1413 (Type, 'translated_class_name', 6), -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/contractsmanagepage.pt
r12097 r12337 5 5 <thead> 6 6 <tr> 7 <th > </th>7 <th tal:condition="view/edit_contracts_allowed"> </th> 8 8 <th i18n:translate="">Id</th> 9 9 <th i18n:translate="">Title</th> … … 14 14 </thead> 15 15 <tbody> 16 <tr tal:repeat="c lcontext/values">17 <td >16 <tr tal:repeat="contract context/values"> 17 <td tal:condition="view/edit_contracts_allowed"> 18 18 <input type="checkbox" 19 name="val_id"20 tal:attributes="value cl/__name__"21 tal:condition="python: not view.unremovable(cl)" />19 name="val_id" 20 tal:attributes="value contract/__name__" 21 tal:condition="python: view.remove_contract_allowed(contract)" /> 22 22 </td> 23 23 <td> 24 <a tal:attributes="href python: view.url(c l)">25 <span tal:content="c l/contract_id">CONID</span></a>24 <a tal:attributes="href python: view.url(contract)"> 25 <span tal:content="contract/contract_id">CONID</span></a> 26 26 </td> 27 27 <td> 28 <span tal:content="c l/title">TITLE</span>28 <span tal:content="contract/title">TITLE</span> 29 29 </td> 30 30 <td> 31 <span tal:content="c l/translated_class_name">CLASSNAME</span>31 <span tal:content="contract/translated_class_name">CLASSNAME</span> 32 32 </td> 33 33 <td> 34 <span tal:content="c l/translated_state">STATE</span>34 <span tal:content="contract/translated_state">STATE</span> 35 35 </td> 36 36 <td> 37 <span tal:content="c l/formatted_transition_date">37 <span tal:content="contract/formatted_transition_date"> 38 38 LASTTRANSITIONDATE 39 39 </span> … … 43 43 </table> 44 44 45 <div tal:condition="python: view.availableActions and view. manage_contracts_allowed">45 <div tal:condition="python: view.availableActions and view.edit_contracts_allowed"> 46 46 <span tal:repeat="action view/actions" 47 47 tal:omit-tag=""> -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/contracts.py
r12336 r12337 132 132 133 133 @property 134 def is_editable _by_customer(self):134 def is_editable(self): 135 135 try: 136 136 # Customer must be approved -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py
r12330 r12337 214 214 'formatted_transition_date', 215 215 'translated_class_name', 216 'is_editable _by_customer',216 'is_editable', 217 217 'is_approvable']))) 218 218 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py
r12336 r12337 290 290 last_product_id = Attribute( 291 291 'Id of product recently stored with the contract') 292 is_editable _by_customer = Attribute('Contract editable by customer')292 is_editable = Attribute('Contract editable by customer and manager') 293 293 is_approvable = Attribute('Contract approvable by officer') 294 294 translated_class_name = Attribute('Translatable class name') -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py
r12214 r12337 33 33 CustomerBaseDisplayFormPage, 34 34 DocumentsManageFormPage, DocumentDisplayFormPage, DocumentManageFormPage, 35 Contracts ManageFormPage, ContractDisplayFormPage,35 ContractsFormPage, ContractDisplayFormPage, 36 36 ContractManageFormPage) 37 37 … … 375 375 grok.order(2) 376 376 grok.context(IContractsContainer) 377 grok.view(Contracts ManageFormPage)377 grok.view(ContractsFormPage) 378 378 grok.require('waeup.viewCustomer') 379 379 icon = 'actionicon_pdf.png' … … 401 401 @property 402 402 def target_url(self): 403 if not self.context.is_editable _by_customer:403 if not self.context.is_editable: 404 404 return '' 405 405 return self.view.url(self.view.context, self.target) -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/interfaces.py
r12336 r12337 58 58 59 59 contract_title = schema.TextLine( 60 title = _(u' Product Title'),61 description = _('Product title i f empty'),60 title = _(u'Contract Title'), 61 description = _('Product title is used if empty.'), 62 62 required = False, 63 63 )
Note: See TracChangeset for help on using the changeset viewer.