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.

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