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.

694 lines
33 KiB

7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
  1. from datetime import datetime
  2. from odoo import api, fields, models, _
  3. from odoo.addons.base_iban.models.res_partner_bank import validate_iban
  4. from odoo.exceptions import UserError, ValidationError
  5. _REQUIRED = ['email',
  6. 'firstname',
  7. 'lastname',
  8. 'birthdate',
  9. 'address',
  10. 'share_product_id',
  11. 'ordered_parts',
  12. 'zip_code',
  13. 'city',
  14. 'iban',
  15. 'no_registre',
  16. 'gender'] # Could be improved including required from model
  17. @api.model
  18. def _lang_get(self):
  19. languages = self.env['res.lang'].search([])
  20. return [(language.code, language.name) for language in languages]
  21. class SubscriptionRequest(models.Model):
  22. _name = 'subscription.request'
  23. _description = 'Subscription Request'
  24. def get_required_field(self):
  25. return _REQUIRED
  26. @api.model
  27. def create(self, vals):
  28. partner_obj = self.env['res.partner']
  29. if not vals.get('partner_id'):
  30. cooperator = False
  31. if vals.get('no_registre'):
  32. cooperator = partner_obj.get_cooperator_from_nin(
  33. vals.get('no_registre'))
  34. if cooperator:
  35. # TODO remove the following line of code once it has
  36. # been founded a way to avoid dubble entry
  37. cooperator = cooperator[0]
  38. if cooperator.member:
  39. vals['type'] = 'increase'
  40. vals['already_cooperator'] = True
  41. else:
  42. vals['type'] = 'subscription'
  43. vals['partner_id'] = cooperator.id
  44. if not cooperator.cooperator:
  45. cooperator.write({'cooperator': True})
  46. else:
  47. cooperator_id = vals.get('partner_id')
  48. cooperator = partner_obj.browse(cooperator_id)
  49. if cooperator.member:
  50. vals['type'] = 'increase'
  51. vals['already_cooperator'] = True
  52. subscr_request = super(SubscriptionRequest, self).create(vals)
  53. confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation', False)
  54. confirmation_mail_template.send_mail(subscr_request.id)
  55. return subscr_request
  56. @api.model
  57. def create_comp_sub_req(self, vals):
  58. vals["name"] = vals['company_name']
  59. if not vals.get('partner_id'):
  60. cooperator = self.env['res.partner'].get_cooperator_from_crn(vals.get('company_register_number'))
  61. if cooperator:
  62. vals['partner_id'] = cooperator.id
  63. vals['type'] = 'increase'
  64. vals['already_cooperator'] = True
  65. subscr_request = super(SubscriptionRequest, self).create(vals)
  66. confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation_company', False)
  67. confirmation_mail_template.send_mail(subscr_request.id, True)
  68. return subscr_request
  69. def check_belgian_identification_id(self, nat_register_num):
  70. if not self.check_empty_string(nat_register_num):
  71. return False
  72. if len(nat_register_num) != 11:
  73. return False
  74. if not nat_register_num.isdigit():
  75. return False
  76. birthday_number = nat_register_num[0:9]
  77. controle = nat_register_num[9:11]
  78. check_controle = 97 - (int(birthday_number) % 97)
  79. if int(check_controle) != int(controle):
  80. check_controle = 97 - ((2000000000 + int(birthday_number)) % 97)
  81. if int(check_controle) != int(controle):
  82. return False
  83. return True
  84. def check_empty_string(self, value):
  85. if value is None or value is False or value == '':
  86. return False
  87. return True
  88. def check_iban(self, iban):
  89. validated = True
  90. try:
  91. validate_iban(iban)
  92. except ValidationError:
  93. validated = False
  94. return validated
  95. @api.multi
  96. @api.depends('iban', 'no_registre', 'skip_control_ng', 'is_company')
  97. def _validated_lines(self):
  98. for sub_request in self:
  99. validated = self.check_iban(sub_request.iban)
  100. if validated and (sub_request.skip_control_ng or
  101. self.check_belgian_identification_id(
  102. sub_request.no_registre)):
  103. validated = True
  104. else:
  105. validated = False
  106. sub_request.validated = validated
  107. @api.multi
  108. @api.depends('share_product_id',
  109. 'share_product_id.list_price',
  110. 'ordered_parts')
  111. def _compute_subscription_amount(self):
  112. for sub_request in self:
  113. sub_request.subscription_amount = (sub_request.share_product_id.
  114. list_price *
  115. sub_request.ordered_parts)
  116. already_cooperator = fields.Boolean(string="I'm already cooperator",
  117. readonly=True,
  118. states={'draft': [('readonly', False)]}
  119. )
  120. name = fields.Char(string='Name',
  121. required=True,
  122. readonly=True,
  123. states={'draft': [('readonly', False)]})
  124. firstname = fields.Char(string='Firstname',
  125. readonly=True,
  126. states={'draft': [('readonly', False)]})
  127. lastname = fields.Char(string='Lastname',
  128. readonly=True,
  129. states={'draft': [('readonly', False)]})
  130. birthdate = fields.Date(string="Birthdate",
  131. readonly=True,
  132. states={'draft': [('readonly', False)]})
  133. gender = fields.Selection([('male', _('Male')),
  134. ('female', _('Female')),
  135. ('other', _('Other'))],
  136. string='Gender',
  137. readonly=True,
  138. states={'draft': [('readonly', False)]})
  139. type = fields.Selection([('new', 'New Cooperator'),
  140. ('subscription', 'Subscription'),
  141. ('increase', 'Increase number of share')],
  142. string='Type', default="new",
  143. readonly=True,
  144. states={'draft': [('readonly', False)]})
  145. state = fields.Selection([('draft', 'Draft'),
  146. ('block', 'Blocked'),
  147. ('done', 'Done'),
  148. ('waiting', 'Waiting'),
  149. ('transfer', 'Transfer'),
  150. ('cancelled', 'Cancelled'),
  151. ('paid', 'paid')],
  152. string='State', required=True, default="draft")
  153. email = fields.Char(string='Email',
  154. required=True,
  155. readonly=True,
  156. states={'draft': [('readonly', False)]})
  157. iban = fields.Char(string='Account Number',
  158. readonly=True,
  159. states={'draft': [('readonly', False)]})
  160. partner_id = fields.Many2one('res.partner',
  161. string='Cooperator',
  162. readonly=True,
  163. states={'draft': [('readonly', False)]})
  164. share_product_id = fields.Many2one('product.product',
  165. string='Share type',
  166. domain=[('is_share', '=', True)],
  167. required=True,
  168. readonly=True,
  169. states={'draft': [('readonly', False)]})
  170. share_short_name = fields.Char(related='share_product_id.short_name',
  171. string='Share type name',
  172. readonly=True,
  173. states={'draft': [('readonly', False)]})
  174. share_unit_price = fields.Float(related='share_product_id.list_price',
  175. string='Share price',
  176. readonly=True,
  177. states={'draft': [('readonly', False)]})
  178. subscription_amount = fields.Float(compute='_compute_subscription_amount',
  179. string='Subscription amount',
  180. readonly=True,
  181. states={'draft': [('readonly', False)]})
  182. ordered_parts = fields.Integer(string='Number of Share',
  183. required=True,
  184. readonly=True,
  185. default=1,
  186. states={'draft': [('readonly', False)]})
  187. address = fields.Char(string='Address',
  188. required=True,
  189. readonly=True,
  190. states={'draft': [('readonly', False)]})
  191. city = fields.Char(string='City',
  192. required=True,
  193. readonly=True,
  194. states={'draft': [('readonly', False)]})
  195. zip_code = fields.Char(string='Zip Code',
  196. required=True,
  197. readonly=True,
  198. states={'draft': [('readonly', False)]})
  199. country_id = fields.Many2one('res.country',
  200. string='Country',
  201. ondelete='restrict',
  202. required=True,
  203. readonly=True,
  204. states={'draft': [('readonly', False)]})
  205. phone = fields.Char(string='Phone',
  206. readonly=True,
  207. states={'draft': [('readonly', False)]})
  208. no_registre = fields.Char(string='National Register Number',
  209. readonly=True,
  210. states={'draft': [('readonly', False)]})
  211. user_id = fields.Many2one('res.users',
  212. string='Responsible',
  213. readonly=True)
  214. validated = fields.Boolean(compute='_validated_lines',
  215. string='Valid Line?',
  216. readonly=True)
  217. skip_control_ng = fields.Boolean(string="Skip control",
  218. help="if this field is checked then no"
  219. " control will be done on the national"
  220. " register number and on the iban bank"
  221. " account. To be done in case of the id"
  222. " card is from abroad or in case of"
  223. " a passport")
  224. lang = fields.Selection(_lang_get,
  225. string='Language',
  226. required=True,
  227. readonly=True,
  228. states={'draft': [('readonly', False)]},
  229. default=lambda self: self.env['res.company']._company_default_get().default_lang_id.code)
  230. date = fields.Date(string='Subscription date request',
  231. required=True,
  232. readonly=True,
  233. states={'draft': [('readonly', False)]},
  234. default=lambda self: datetime.strftime(datetime.now(),
  235. '%Y-%m-%d'))
  236. company_id = fields.Many2one('res.company',
  237. string='Company',
  238. required=True,
  239. change_default=True,
  240. readonly=True,
  241. default=lambda self: self.env['res.company']._company_default_get())
  242. is_company = fields.Boolean(string='Is a company',
  243. readonly=True,
  244. states={'draft': [('readonly', False)]})
  245. is_operation = fields.Boolean(string='Is an operation',
  246. readonly=True,
  247. states={'draft': [('readonly', False)]})
  248. company_name = fields.Char(string="Company name",
  249. readonly=True,
  250. states={'draft': [('readonly', False)]})
  251. company_email = fields.Char(string="Company email",
  252. readonly=True,
  253. states={'draft': [('readonly', False)]})
  254. company_register_number = fields.Char(string='Company register number',
  255. readonly=True,
  256. states={'draft': [('readonly', False)]})
  257. company_type = fields.Selection([('scrl', 'SCRL'),
  258. ('asbl', 'ASBL'),
  259. ('sprl', 'SPRL'),
  260. ('sa', 'SA'),
  261. ('other', 'Other')],
  262. string="Company type",
  263. readonly=True,
  264. states={'draft': [('readonly', False)]})
  265. same_address = fields.Boolean(string='Same address',
  266. readonly=True,
  267. states={'draft': [('readonly', False)]})
  268. activities_address = fields.Char(string='Activities address',
  269. readonly=True,
  270. states={'draft': [('readonly', False)]})
  271. activities_city = fields.Char(string='Activities city',
  272. readonly=True,
  273. states={'draft': [('readonly', False)]})
  274. activities_zip_code = fields.Char(string='Activities zip Code',
  275. readonly=True,
  276. states={'draft': [('readonly', False)]})
  277. activities_country_id = fields.Many2one('res.country',
  278. string='Activities country',
  279. ondelete='restrict',
  280. readonly=True,
  281. states={'draft': [('readonly', False)]})
  282. contact_person_function = fields.Char(string='Function',
  283. readonly=True,
  284. states={'draft': [('readonly', False)]})
  285. operation_request_id = fields.Many2one('operation.request',
  286. string="Operation Request",
  287. readonly=True,
  288. states={'draft': [('readonly', False)]})
  289. capital_release_request = fields.One2many('account.invoice',
  290. 'subscription_request',
  291. string='Capital release request',
  292. readonly=True,
  293. states={'draft': [('readonly', False)]})
  294. capital_release_request_date = fields.Date(string="Force the capital "
  295. "release request date",
  296. help="Keep empty to use the "
  297. "current date",
  298. copy=False,
  299. readonly=True,
  300. states={'draft': [('readonly', False)]})
  301. source = fields.Selection([('website', 'Website'),
  302. ('crm', 'CRM'),
  303. ('manual', 'Manual'),
  304. ('operation', 'Operation')],
  305. string="Source",
  306. default="website",
  307. readonly=True,
  308. states={'draft': [('readonly', False)]})
  309. _order = "id desc"
  310. def get_person_info(self, partner):
  311. self.firstname = partner.firstname
  312. self.name = partner.name
  313. self.lastname = partner.lastname
  314. self.no_registre = partner.national_register_number
  315. self.email = partner.email
  316. self.birthdate = partner.birthdate_date
  317. self.gender = partner.gender
  318. self.address = partner.street
  319. self.city = partner.city
  320. self.zip_code = partner.zip
  321. self.country_id = partner.country_id
  322. self.phone = partner.phone
  323. self.lang = partner.lang
  324. @api.onchange('partner_id')
  325. def onchange_partner(self):
  326. partner = self.partner_id
  327. if partner:
  328. self.is_company = partner.is_company
  329. self.already_cooperator = partner.member
  330. if partner.bank_ids:
  331. self.iban = partner.bank_ids[0].acc_number
  332. if partner.member:
  333. self.type = 'increase'
  334. if partner.is_company:
  335. self.company_name = partner.name
  336. self.company_email = partner.email
  337. self.company_register_number = partner.company_register_number
  338. representative = partner.get_representative()
  339. self.get_person_info(representative)
  340. self.contact_person_function = representative.function
  341. else:
  342. self.get_person_info(partner)
  343. # declare this function in order to be overriden
  344. def get_eater_vals(self, partner, share_product_id): #noqa
  345. return {}
  346. def _prepare_invoice_line(self, product, partner, qty):
  347. self.ensure_one()
  348. account = product.property_account_income_id \
  349. or product.categ_id.property_account_income_categ_id
  350. if not account:
  351. raise UserError(_('Please define income account for this product:'
  352. ' "%s" (id:%d) - or for its category: "%s".') %
  353. (product.name, product.id, product.categ_id.name))
  354. fpos = partner.property_account_position_id
  355. if fpos:
  356. account = fpos.map_account(account)
  357. res = {
  358. 'name': product.name,
  359. 'account_id': account.id,
  360. 'price_unit': product.lst_price,
  361. 'quantity': qty,
  362. 'uom_id': product.uom_id.id,
  363. 'product_id': product.id or False,
  364. }
  365. return res
  366. def send_capital_release_request(self, invoice):
  367. invoice_email_template = self.env['mail.template'].search([('name', '=', 'Request to Release Capital - Send by Email')])[0]
  368. # we send the email with the capital release request in attachment
  369. invoice_email_template.send_mail(invoice.id, True)
  370. invoice.sent = True
  371. def get_journal(self):
  372. return self.env['account.journal'].search([('code', '=', 'SUBJ')])[0]
  373. def create_invoice(self, partner):
  374. # get subscription journal
  375. journal = self.get_journal()
  376. # get the account for associate
  377. if self.company_id.property_cooperator_account:
  378. account = self.company_id.property_cooperator_account
  379. else:
  380. account = self.env['account.account'].search([('code', '=', '416000')])[0]
  381. # creating invoice and invoice lines
  382. invoice_vals = {'partner_id': partner.id,
  383. 'journal_id': journal.id,
  384. 'account_id': account.id,
  385. 'type': 'out_invoice',
  386. 'release_capital_request': True,
  387. 'subscription_request': self.id}
  388. if self.capital_release_request_date:
  389. invoice_vals['date_invoice'] = self.capital_release_request_date
  390. invoice = self.env['account.invoice'].create(invoice_vals)
  391. vals = self._prepare_invoice_line(self.share_product_id, partner,
  392. self.ordered_parts)
  393. vals['invoice_id'] = invoice.id
  394. self.env['account.invoice.line'].create(vals)
  395. # validate the capital release request
  396. invoice.action_invoice_open()
  397. self.send_capital_release_request(invoice)
  398. return invoice
  399. def get_partner_company_vals(self):
  400. partner_vals = {'name': self.company_name,
  401. 'last_name': self.company_name,
  402. 'is_company': self.is_company,
  403. 'company_register_number': self.company_register_number, #noqa
  404. 'customer': False, 'cooperator': True,
  405. 'street': self.address, 'zip': self.zip_code,
  406. 'city': self.city, 'email': self.company_email,
  407. 'out_inv_comm_type': 'bba',
  408. 'customer': self.share_product_id.customer,
  409. 'out_inv_comm_algorithm': 'random',
  410. 'country_id': self.country_id.id,
  411. 'lang': self.lang}
  412. return partner_vals
  413. def get_partner_vals(self):
  414. partner_vals = {'name': self.name, 'firstname': self.firstname,
  415. 'lastname': self.lastname, 'street': self.address,
  416. 'zip': self.zip_code, 'email': self.email,
  417. 'gender': self.gender, 'cooperator': True,
  418. 'city': self.city, 'phone': self.phone,
  419. 'national_register_number': self.no_registre,
  420. 'out_inv_comm_type': 'bba',
  421. 'out_inv_comm_algorithm': 'random',
  422. 'country_id': self.country_id.id, 'lang': self.lang,
  423. 'birthdate_date': self.birthdate,
  424. 'customer': self.share_product_id.customer}
  425. return partner_vals
  426. def create_coop_partner(self):
  427. partner_obj = self.env['res.partner']
  428. if self.is_company:
  429. partner_vals = self.get_partner_company_vals()
  430. else:
  431. partner_vals = self.get_partner_vals()
  432. partner = partner_obj.create(partner_vals)
  433. if self.iban:
  434. self.env['res.partner.bank'].create({
  435. 'partner_id': partner.id,
  436. 'acc_number': self.iban
  437. })
  438. return partner
  439. @api.one
  440. def validate_subscription_request(self):
  441. partner_obj = self.env['res.partner']
  442. if self.ordered_parts <= 0:
  443. raise UserError(_('Number of share must be greater than 0.'))
  444. if self.partner_id:
  445. if not self.partner_id.cooperator:
  446. self.partner_id.cooperator = True
  447. partner = self.partner_id
  448. else:
  449. partner = None
  450. domain = []
  451. if self.already_cooperator:
  452. raise UserError(_('The checkbox already cooperator is'
  453. ' checked please select a cooperator.'))
  454. elif self.is_company and self.company_register_number:
  455. domain = [('company_register_number', '=', self.company_register_number)] #noqa
  456. elif not self.is_company and self.no_registre:
  457. domain = [('national_register_number', '=', self.no_registre)]
  458. if domain:
  459. partner = partner_obj.search(domain)
  460. if not partner:
  461. partner = self.create_coop_partner()
  462. else:
  463. partner = partner[0]
  464. if self.is_company and not partner.has_representative():
  465. contact = False
  466. if self.no_registre:
  467. domain = [('national_register_number', '=', self.no_registre)]
  468. contact = partner_obj.search(domain)
  469. if contact:
  470. contact.type = 'representative'
  471. if not contact:
  472. contact_vals = {'name': self.name,
  473. 'firstname': self.firstname,
  474. 'lastname': self.lastname, 'customer': False,
  475. 'is_company': False, 'cooperator': True,
  476. 'street': self.address, 'gender': self.gender,
  477. 'zip': self.zip_code, 'city': self.city,
  478. 'phone': self.phone, 'email': self.email,
  479. 'national_register_number': self.no_registre,
  480. 'country_id': self.country_id.id,
  481. 'out_inv_comm_type': 'bba',
  482. 'out_inv_comm_algorithm': 'random',
  483. 'lang': self.lang,
  484. 'birthdate_date': self.birthdate,
  485. 'parent_id': partner.id,
  486. 'representative': True,
  487. 'function': self.contact_person_function,
  488. 'type': 'representative'}
  489. contact = partner_obj.create(contact_vals)
  490. else:
  491. if len(contact) > 1:
  492. raise UserError(_('There is two different persons with the'
  493. ' same national register number. Please'
  494. ' proceed to a merge before to continue')
  495. )
  496. if contact.parent_id and contact.parent_id.id != partner.id:
  497. raise UserError(_('This contact person is already defined'
  498. ' for another company. Please select'
  499. ' another contact'))
  500. else:
  501. contact.write({'parent_id': partner.id,
  502. 'representative': True})
  503. invoice = self.create_invoice(partner)
  504. self.write({'partner_id': partner.id, 'state': 'done'})
  505. return invoice
  506. @api.one
  507. def block_subscription_request(self):
  508. self.write({'state': 'block'})
  509. @api.one
  510. def unblock_subscription_request(self):
  511. self.write({'state': 'draft'})
  512. @api.one
  513. def cancel_subscription_request(self):
  514. self.write({'state': 'cancelled'})
  515. @api.one
  516. def put_on_waiting_list(self):
  517. self.write({'state': 'waiting'})
  518. class ShareLine(models.Model):
  519. _name = 'share.line'
  520. _description = "Share line"
  521. @api.multi
  522. def _compute_total_line(self):
  523. res = {}
  524. for line in self:
  525. line.total_amount_line = line.share_unit_price * line.share_number
  526. return res
  527. share_product_id = fields.Many2one('product.product',
  528. string='Share type',
  529. required=True,
  530. readonly=True)
  531. share_number = fields.Integer(string='Number of Share',
  532. required=True,
  533. readonly=True)
  534. share_short_name = fields.Char(related='share_product_id.short_name',
  535. string='Share type name',
  536. readonly=True)
  537. share_unit_price = fields.Float(string='Share price',
  538. readonly=True)
  539. effective_date = fields.Date(string='Effective Date',
  540. readonly=True)
  541. partner_id = fields.Many2one('res.partner',
  542. string='Cooperator',
  543. required=True,
  544. ondelete='cascade',
  545. readonly=True)
  546. total_amount_line = fields.Float(compute='_compute_total_line',
  547. string='Total amount line')
  548. class SubscriptionRegister(models.Model):
  549. _name = 'subscription.register'
  550. _description = "Subscription register"
  551. @api.multi
  552. def _compute_total_line(self):
  553. for register_line in self:
  554. register_line.total_amount_line = register_line.share_unit_price * register_line.quantity
  555. name = fields.Char(string='Number Operation',
  556. required=True,
  557. readonly=True)
  558. register_number_operation = fields.Integer(string='Register Number Operation',
  559. required=True,
  560. readonly=True)
  561. partner_id = fields.Many2one('res.partner',
  562. string='Cooperator',
  563. required=True,
  564. readonly=True)
  565. partner_id_to = fields.Many2one('res.partner',
  566. string='Transfered to',
  567. readonly=True)
  568. date = fields.Date(string='Subscription Date',
  569. required=True,
  570. readonly=True)
  571. quantity = fields.Integer(string='Number of share',
  572. readonly=True)
  573. share_unit_price = fields.Float(string='Share price',
  574. readonly=True)
  575. total_amount_line = fields.Float(compute='_compute_total_line',
  576. string='Total amount line')
  577. share_product_id = fields.Many2one('product.product',
  578. string='Share type',
  579. required=True,
  580. readonly=True,
  581. domain=[('is_share', '=', True)])
  582. share_short_name = fields.Char(related='share_product_id.short_name',
  583. string='Share type name',
  584. readonly=True)
  585. share_to_product_id = fields.Many2one('product.product',
  586. string='Share to type',
  587. readonly=True,
  588. domain=[('is_share', '=', True)])
  589. share_to_short_name = fields.Char(related='share_to_product_id.short_name',
  590. string='Share to type name',
  591. readonly=True)
  592. quantity_to = fields.Integer(string='Number of share to',
  593. readonly=True)
  594. share_to_unit_price = fields.Float(string='Share to price',
  595. readonly=True)
  596. type = fields.Selection([('subscription', 'Subscription'),
  597. ('transfer', 'Transfer'),
  598. ('sell_back', 'Sell Back'),
  599. ('convert', 'Conversion')],
  600. string='Operation Type', readonly=True)
  601. company_id = fields.Many2one('res.company', string='Company',
  602. required=True,
  603. change_default=True, readonly=True,
  604. default=lambda self: self.env['res.company']._company_default_get())
  605. user_id = fields.Many2one('res.users',
  606. string='Responsible',
  607. readonly=True,
  608. default=lambda self: self.env.user)
  609. _order = "register_number_operation asc"
  610. @api.model
  611. def read_group(self, domain, fields, groupby, offset=0, limit=None,
  612. orderby=False,
  613. lazy=True):
  614. if 'share_unit_price' in fields:
  615. fields.remove('share_unit_price')
  616. if 'register_number_operation' in fields:
  617. fields.remove('register_number_operation')
  618. res = super(SubscriptionRegister, self).read_group(domain, fields,
  619. groupby,
  620. offset=offset,
  621. limit=limit,
  622. orderby=orderby,
  623. lazy=lazy)
  624. if 'total_amount_line' in fields:
  625. for line in res:
  626. if '__domain' in line:
  627. lines = self.search(line['__domain'])
  628. inv_value = 0.0
  629. for line2 in lines:
  630. inv_value += line2.total_amount_line
  631. line['total_amount_line'] = inv_value
  632. return res