You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

381 lines
16 KiB

[ADD] bond and loan issues management [ADD] bond and loan issues management module skeleton [IMP] change increase menu sequence [IMP] add models, fields and views [IMP] add xml declaration in head of file [ADD] add easy_my_coop_loan_website - WIP [IMP] add access rights [IMP] this raise inconsistency so replace id by default_code. [IMP] change import openerp to odoo [IMP] add website loan module [FIX] put website display in loan [FIX] fix import [FIX] fix function [IMP] use correct name [IMP] make the loan and bond visible [IMP] add js, field and logic to set amount limit per subscription [IMP] remove dependency on recaptcha as user is logged to subscribe [IMP] add fields [IMP] save loan issue subscription still in WIP [IMP] remove alert pop up [IMP] add dependency to easy_my_coop_website [IMP] remove force send for sub request creation email notification [IMP] add mail templates [IMP] save subscription in the corresponding loan issue. add email notif [FIX] fix loan issue line view [FIX] add related field to loan issue. It is where the data stand [IMP] move term_view up [FIX] fix js error when false is returned [FIX] fix function when loan_issue_id in None [IMP] add actions and button [FIX] fix action [FIX] fix mail template [IMP] set noupdate=1 [IMP] change order [IMP] display loan issue lines on partner form [IMP] add loan view in partner form [IMP] add face value on loan issue and line add face value on loan issue and line. add as well the quantity and computation of the amount [FIX] missing id overriding values wasn't working [IMP] getting bond face value and setting it as step. [IMP] subscribed_amount computed field is the sum of the amount lines [IMP] allow a waiting payment to be cancelled [IMP] make field required [REFACT] move loan issue line code to dedicated file [IMP] add interest calculation and model [ADD] bond and loan issues management module skeleton [IMP] add models, fields and views [IMP] allow creation by hand [IMP] adding partner related field [IMP] put code in separate function [FIX] pass it to get method [IMP] routes consistent form [FIX] fix eof [FIX] GET is working for ajax call [IMP] website page for loan issue subscription
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
[ADD] bond and loan issues management [ADD] bond and loan issues management module skeleton [IMP] change increase menu sequence [IMP] add models, fields and views [IMP] add xml declaration in head of file [ADD] add easy_my_coop_loan_website - WIP [IMP] add access rights [IMP] this raise inconsistency so replace id by default_code. [IMP] change import openerp to odoo [IMP] add website loan module [FIX] put website display in loan [FIX] fix import [FIX] fix function [IMP] use correct name [IMP] make the loan and bond visible [IMP] add js, field and logic to set amount limit per subscription [IMP] remove dependency on recaptcha as user is logged to subscribe [IMP] add fields [IMP] save loan issue subscription still in WIP [IMP] remove alert pop up [IMP] add dependency to easy_my_coop_website [IMP] remove force send for sub request creation email notification [IMP] add mail templates [IMP] save subscription in the corresponding loan issue. add email notif [FIX] fix loan issue line view [FIX] add related field to loan issue. It is where the data stand [IMP] move term_view up [FIX] fix js error when false is returned [FIX] fix function when loan_issue_id in None [IMP] add actions and button [FIX] fix action [FIX] fix mail template [IMP] set noupdate=1 [IMP] change order [IMP] display loan issue lines on partner form [IMP] add loan view in partner form [IMP] add face value on loan issue and line add face value on loan issue and line. add as well the quantity and computation of the amount [FIX] missing id overriding values wasn't working [IMP] getting bond face value and setting it as step. [IMP] subscribed_amount computed field is the sum of the amount lines [IMP] allow a waiting payment to be cancelled [IMP] make field required [REFACT] move loan issue line code to dedicated file [IMP] add interest calculation and model [ADD] bond and loan issues management module skeleton [IMP] add models, fields and views [IMP] allow creation by hand [IMP] adding partner related field [IMP] put code in separate function [FIX] pass it to get method [IMP] routes consistent form [FIX] fix eof [FIX] GET is working for ajax call [IMP] website page for loan issue subscription
5 years ago
5 years ago
5 years ago
6 years ago
  1. import base64
  2. from datetime import datetime
  3. import re
  4. from odoo import http
  5. from odoo.http import request
  6. from odoo.tools.translate import _
  7. # Only use for behavior, don't stock it
  8. _TECHNICAL = ['view_from', 'view_callback']
  9. # Allow in description
  10. _BLACKLIST = ['id', 'create_uid', 'create_date', 'write_uid', 'write_date',
  11. 'user_id', 'active']
  12. _COOP_FORM_FIELD = ['email', 'confirm_email', 'firstname', 'lastname',
  13. 'birthdate', 'iban', 'share_product_id',
  14. 'address', 'city', 'zip_code', 'country_id', 'phone',
  15. 'lang', 'nb_parts', 'total_parts', 'error_msg']
  16. _COMPANY_FORM_FIELD = ['is_company', 'company_register_number', 'company_name',
  17. 'company_email', 'confirm_email', 'email', 'firstname',
  18. 'lastname', 'birthdate', 'iban', 'share_product_id',
  19. 'address', 'city', 'zip_code', 'country_id', 'phone',
  20. 'lang', 'nb_parts', 'total_parts', 'error_msg',
  21. 'company_type']
  22. class WebsiteSubscription(http.Controller):
  23. @http.route(['/page/become_cooperator',
  24. '/become_cooperator'],
  25. type='http', auth="public", website=True)
  26. def display_become_cooperator_page(self, **kwargs):
  27. values = {}
  28. logged = False
  29. if request.env.user.login != 'public':
  30. logged = True
  31. partner = request.env.user.partner_id
  32. if partner.is_company:
  33. return self.display_become_company_cooperator_page()
  34. values = self.fill_values(values, False, logged, True)
  35. for field in _COOP_FORM_FIELD:
  36. if kwargs.get(field):
  37. values[field] = kwargs.pop(field)
  38. values.update(kwargs=kwargs.items())
  39. return request.render("easy_my_coop_website.becomecooperator", values)
  40. @http.route(['/page/become_company_cooperator',
  41. '/become_company_cooperator'],
  42. type='http', auth="public", website=True)
  43. def display_become_company_cooperator_page(self, **kwargs):
  44. values = {}
  45. logged = False
  46. if request.env.user.login != 'public':
  47. logged = True
  48. values = self.fill_values(values, True, logged, True)
  49. for field in _COMPANY_FORM_FIELD:
  50. if kwargs.get(field):
  51. values[field] = kwargs.pop(field)
  52. values.update(kwargs=kwargs.items())
  53. return request.render("easy_my_coop_website.becomecompanycooperator",
  54. values)
  55. def preRenderThanks(self, values, kwargs):
  56. """ Allow to be overrided """
  57. return {
  58. '_values': values,
  59. '_kwargs': kwargs,
  60. }
  61. def get_subscription_response(self, values, kwargs):
  62. values = self.preRenderThanks(values, kwargs)
  63. return request.render("easy_my_coop_website.cooperator_thanks", values)
  64. def get_date_string(self, birthdate):
  65. if birthdate:
  66. return datetime.strftime(birthdate, "%d/%m/%Y")
  67. return False
  68. def get_values_from_user(self, values, is_company):
  69. # the subscriber is connected
  70. if request.env.user.login != 'public':
  71. values['logged'] = 'on'
  72. partner = request.env.user.partner_id
  73. if partner.member or partner.old_member:
  74. values['already_cooperator'] = 'on'
  75. if partner.bank_ids:
  76. values['iban'] = partner.bank_ids[0].acc_number
  77. values['address'] = partner.street
  78. values['zip_code'] = partner.zip
  79. values['city'] = partner.city
  80. values['country_id'] = partner.country_id.id
  81. if is_company:
  82. # company values
  83. values['company_register_number'] = partner.company_register_number
  84. values['company_name'] = partner.name
  85. values['company_email'] = partner.email
  86. values['company_type'] = partner.legal_form
  87. # contact person values
  88. representative = partner.get_representative()
  89. values['firstname'] = representative.firstname
  90. values['lastname'] = representative.lastname
  91. values['gender'] = representative.gender
  92. values['email'] = representative.email
  93. values['contact_person_function'] = representative.function
  94. values['birthdate'] = self.get_date_string(representative.birthdate_date)
  95. values['lang'] = representative.lang
  96. values['phone'] = representative.phone
  97. else:
  98. values['firstname'] = partner.firstname
  99. values['lastname'] = partner.lastname
  100. values['email'] = partner.email
  101. values['gender'] = partner.gender
  102. values['birthdate'] = self.get_date_string(partner.birthdate_date)
  103. values['lang'] = partner.lang
  104. values['phone'] = partner.phone
  105. return values
  106. def fill_values(self, values, is_company, logged, load_from_user=False):
  107. sub_req_obj = request.env['subscription.request']
  108. company = request.website.company_id
  109. products = self.get_products_share(is_company)
  110. if load_from_user:
  111. values = self.get_values_from_user(values, is_company)
  112. if is_company:
  113. values['is_company'] = 'on'
  114. if logged:
  115. values['logged'] = 'on'
  116. values['countries'] = self.get_countries()
  117. values['langs'] = self.get_langs()
  118. values['products'] = products
  119. fields_desc = sub_req_obj.sudo().fields_get(['company_type', 'gender'])
  120. values['company_types'] = fields_desc['company_type']['selection']
  121. values['genders'] = fields_desc['gender']['selection']
  122. values['company'] = company
  123. if not values.get('share_product_id'):
  124. for product in products:
  125. if product.default_share_product is True:
  126. values['share_product_id'] = product.id
  127. break
  128. if not values.get('share_product_id', False) and products:
  129. values['share_product_id'] = products[0].id
  130. if not values.get('country_id'):
  131. if company.default_country_id:
  132. values['country_id'] = company.default_country_id.id
  133. else:
  134. values['country_id'] = '21'
  135. if not values.get('activities_country_id'):
  136. if company.default_country_id:
  137. values['activities_country_id'] = company.default_country_id.id
  138. else:
  139. values['activities_country_id'] = '21'
  140. if not values.get('lang'):
  141. if company.default_lang_id:
  142. values['lang'] = company.default_lang_id.code
  143. comp = request.env['res.company']._company_default_get()
  144. values.update({
  145. 'display_data_policy': comp.display_data_policy_approval,
  146. 'data_policy_required': comp.data_policy_approval_required,
  147. 'data_policy_text': comp.data_policy_approval_text,
  148. 'display_internal_rules': comp.display_internal_rules_approval,
  149. 'internal_rules_required': comp.internal_rules_approval_required,
  150. 'internal_rules_text': comp.internal_rules_approval_text,
  151. })
  152. return values
  153. def get_products_share(self, is_company):
  154. product_obj = request.env['product.template']
  155. products = product_obj.sudo().get_web_share_products(is_company)
  156. return products
  157. def get_countries(self):
  158. countries = request.env['res.country'].sudo().search([])
  159. return countries
  160. def get_langs(self):
  161. langs = request.env['res.lang'].sudo().search([])
  162. return langs
  163. def get_selected_share(self, kwargs):
  164. prod_obj = request.env['product.template']
  165. product_id = kwargs.get("share_product_id")
  166. return prod_obj.sudo().browse(int(product_id)).product_variant_ids[0]
  167. def validation(self, kwargs, logged, values, post_file):
  168. user_obj = request.env['res.users']
  169. sub_req_obj = request.env['subscription.request']
  170. redirect = "easy_my_coop_website.becomecooperator"
  171. email = kwargs.get('email')
  172. is_company = kwargs.get("is_company") == 'on'
  173. if is_company:
  174. is_company = True
  175. redirect = "easy_my_coop_website.becomecompanycooperator"
  176. email = kwargs.get('company_email')
  177. # Original place for Google Captcha.
  178. # Maybe https://github.com/lepture/captcha could help on replacing it
  179. # Check that required field from model subscription_request exists
  180. required_fields = sub_req_obj.sudo().get_required_field()
  181. error = set(field for field in required_fields if not values.get(field)) #noqa
  182. if error:
  183. values = self.fill_values(values, is_company, logged)
  184. values["error_msg"] = _("Some mandatory fields have not "
  185. "been filled")
  186. values = dict(values, error=error, kwargs=kwargs.items())
  187. return request.render(redirect, values)
  188. if not logged and email:
  189. user = user_obj.sudo().search([('login', '=', email)])
  190. if user:
  191. values = self.fill_values(values, is_company, logged)
  192. values.update(kwargs)
  193. values["error_msg"] = _("There is an existing account for this"
  194. " mail address. Please login before "
  195. "fill in the form")
  196. return request.render(redirect, values)
  197. else:
  198. confirm_email = kwargs.get('confirm_email')
  199. if email != confirm_email:
  200. values = self.fill_values(values, is_company, logged)
  201. values.update(kwargs)
  202. values["error_msg"] = _("The email and the confirmation "
  203. "email doesn't match.Please check "
  204. "the given mail addresses")
  205. return request.render(redirect, values)
  206. company = request.website.company_id
  207. if company.allow_id_card_upload:
  208. if not post_file:
  209. values = self.fill_values(values, is_company, logged)
  210. values.update(kwargs)
  211. values["error_msg"] = _("You need to upload a"
  212. " scan of your id card")
  213. return request.render(redirect, values)
  214. iban = kwargs.get("iban")
  215. valid = sub_req_obj.check_iban(iban)
  216. if not valid:
  217. values = self.fill_values(values, is_company, logged)
  218. values["error_msg"] = _("You iban account number"
  219. "is not valid")
  220. return request.render(redirect, values)
  221. # check the subscription's amount
  222. max_amount = company.subscription_maximum_amount
  223. if logged:
  224. partner = request.env.user.partner_id
  225. if partner.member:
  226. max_amount = max_amount - partner.total_value
  227. if company.unmix_share_type:
  228. share = self.get_selected_share(kwargs)
  229. if partner.cooperator_type != share.default_code:
  230. values = self.fill_values(values, is_company, logged)
  231. values["error_msg"] = (_("You can't subscribe two "
  232. "different types of share"))
  233. return request.render(redirect, values)
  234. total_amount = float(kwargs.get('total_parts'))
  235. if max_amount > 0 and total_amount > max_amount:
  236. values = self.fill_values(values, is_company, logged)
  237. values["error_msg"] = (_("You can't subscribe for an amount that "
  238. "exceed ")
  239. + str(max_amount)
  240. + company.currency_id.symbol)
  241. return request.render(redirect, values)
  242. return True
  243. @http.route(['/subscription/get_share_product'],
  244. type='json',
  245. auth="public",
  246. methods=['POST'], website=True)
  247. def get_share_product(self, share_product_id, **kw):
  248. product_template = request.env['product.template']
  249. product = product_template.sudo().browse(int(share_product_id))
  250. return {
  251. product.id: {
  252. 'list_price': product.list_price,
  253. 'min_qty': product.minimum_quantity,
  254. 'force_min_qty': product.force_min_qty
  255. }
  256. }
  257. @http.route(['/subscription/subscribe_share'],
  258. type='http',
  259. auth="public", website=True)
  260. def share_subscription(self, **kwargs):
  261. sub_req_obj = request.env['subscription.request']
  262. attach_obj = request.env['ir.attachment']
  263. # List of file to add to ir_attachment once we have the ID
  264. post_file = []
  265. # Info to add after the message
  266. post_description = []
  267. values = {}
  268. for field_name, field_value in kwargs.items():
  269. if hasattr(field_value, 'filename'):
  270. post_file.append(field_value)
  271. elif (field_name in sub_req_obj._fields
  272. and field_name not in _BLACKLIST):
  273. values[field_name] = field_value
  274. # allow to add some free fields or blacklisted field like ID
  275. elif field_name not in _TECHNICAL:
  276. post_description.append("%s: %s" % (field_name, field_value))
  277. logged = kwargs.get("logged") == 'on'
  278. is_company = kwargs.get("is_company") == 'on'
  279. response = self.validation(kwargs, logged, values, post_file)
  280. if response is not True:
  281. return response
  282. already_coop = False
  283. if logged:
  284. partner = request.env.user.partner_id
  285. values['partner_id'] = partner.id
  286. already_coop = partner.member
  287. elif kwargs.get("already_cooperator") == 'on':
  288. already_coop = True
  289. values["already_cooperator"] = already_coop
  290. values["is_company"] = is_company
  291. if kwargs.get('data_policy_approved', 'off') == 'on':
  292. values['data_policy_approved'] = True
  293. if kwargs.get('internal_rules_approved', 'off') == 'on':
  294. values['internal_rules_approved'] = True
  295. lastname = kwargs.get("lastname").upper()
  296. firstname = kwargs.get("firstname").title()
  297. values["name"] = firstname + " " + lastname
  298. values["lastname"] = lastname
  299. values["firstname"] = firstname
  300. values["birthdate"] = datetime.strptime(kwargs.get("birthdate"),
  301. "%d/%m/%Y").date()
  302. values["source"] = "website"
  303. values["share_product_id"] = self.get_selected_share(kwargs).id
  304. if is_company:
  305. if kwargs.get("company_register_number", is_company):
  306. values["company_register_number"] = re.sub('[^0-9a-zA-Z]+',
  307. '',
  308. kwargs.get("company_register_number"))
  309. subscription_id = sub_req_obj.sudo().create_comp_sub_req(values)
  310. else:
  311. subscription_id = sub_req_obj.sudo().create(values)
  312. if subscription_id:
  313. for field_value in post_file:
  314. attachment_value = {
  315. 'name': field_value.filename,
  316. 'res_name': field_value.filename,
  317. 'res_model': 'subscription.request',
  318. 'res_id': subscription_id,
  319. 'datas': base64.encodestring(field_value.read()),
  320. 'datas_fname': field_value.filename,
  321. }
  322. attach_obj.sudo().create(attachment_value)
  323. return self.get_subscription_response(values, kwargs)