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.

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