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.

722 lines
32 KiB

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