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.

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