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.

707 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. invoice_email_template.send_mail(invoice.id, True)
  373. invoice.sent = True
  374. def get_journal(self):
  375. return self.env['account.journal'].search([('code', '=', 'SUBJ')])[0]
  376. def get_accounting_account(self):
  377. account_obj = self.env['account.account']
  378. if self.company_id.property_cooperator_account:
  379. account = self.company_id.property_cooperator_account
  380. else:
  381. account = account_obj.search([('code', '=', '416000')])[0]
  382. return account
  383. def get_invoice_vals(self, partner):
  384. return {
  385. 'partner_id': partner.id,
  386. 'journal_id': self.get_journal().id,
  387. 'account_id': self.get_accounting_account().id,
  388. 'type': 'out_invoice',
  389. 'release_capital_request': True,
  390. 'subscription_request': self.id
  391. }
  392. def create_invoice(self, partner):
  393. # creating invoice and invoice lines
  394. invoice_vals = self.get_invoice_vals(partner)
  395. if self.capital_release_request_date:
  396. invoice_vals['date_invoice'] = self.capital_release_request_date
  397. invoice = self.env['account.invoice'].create(invoice_vals)
  398. vals = self._prepare_invoice_line(self.share_product_id, partner,
  399. self.ordered_parts)
  400. vals['invoice_id'] = invoice.id
  401. self.env['account.invoice.line'].create(vals)
  402. # validate the capital release request
  403. invoice.action_invoice_open()
  404. self.send_capital_release_request(invoice)
  405. return invoice
  406. def get_partner_company_vals(self):
  407. partner_vals = {'name': self.company_name,
  408. 'last_name': self.company_name,
  409. 'is_company': self.is_company,
  410. 'company_register_number': self.company_register_number, #noqa
  411. 'customer': False, 'cooperator': True,
  412. 'street': self.address, 'zip': self.zip_code,
  413. 'city': self.city, 'email': self.company_email,
  414. 'out_inv_comm_type': 'bba',
  415. 'customer': self.share_product_id.customer,
  416. 'out_inv_comm_algorithm': 'random',
  417. 'country_id': self.country_id.id,
  418. 'lang': self.lang}
  419. return partner_vals
  420. def get_partner_vals(self):
  421. partner_vals = {'name': self.name, 'firstname': self.firstname,
  422. 'lastname': self.lastname, 'street': self.address,
  423. 'zip': self.zip_code, 'email': self.email,
  424. 'gender': self.gender, 'cooperator': True,
  425. 'city': self.city, 'phone': self.phone,
  426. 'national_register_number': self.no_registre,
  427. 'out_inv_comm_type': 'bba',
  428. 'out_inv_comm_algorithm': 'random',
  429. 'country_id': self.country_id.id, 'lang': self.lang,
  430. 'birthdate_date': self.birthdate,
  431. 'customer': self.share_product_id.customer}
  432. return partner_vals
  433. def create_coop_partner(self):
  434. partner_obj = self.env['res.partner']
  435. if self.is_company:
  436. partner_vals = self.get_partner_company_vals()
  437. else:
  438. partner_vals = self.get_partner_vals()
  439. partner = partner_obj.create(partner_vals)
  440. if self.iban:
  441. self.env['res.partner.bank'].create({
  442. 'partner_id': partner.id,
  443. 'acc_number': self.iban
  444. })
  445. return partner
  446. @api.one
  447. def validate_subscription_request(self):
  448. partner_obj = self.env['res.partner']
  449. if self.ordered_parts <= 0:
  450. raise UserError(_('Number of share must be greater than 0.'))
  451. if self.partner_id:
  452. if not self.partner_id.cooperator:
  453. self.partner_id.cooperator = True
  454. partner = self.partner_id
  455. else:
  456. partner = None
  457. domain = []
  458. if self.already_cooperator:
  459. raise UserError(_('The checkbox already cooperator is'
  460. ' checked please select a cooperator.'))
  461. elif self.is_company and self.company_register_number:
  462. domain = [('company_register_number', '=', self.company_register_number)] #noqa
  463. elif not self.is_company and self.no_registre:
  464. domain = [('national_register_number', '=', self.no_registre)]
  465. if domain:
  466. partner = partner_obj.search(domain)
  467. if not partner:
  468. partner = self.create_coop_partner()
  469. else:
  470. partner = partner[0]
  471. if self.is_company and not partner.has_representative():
  472. contact = False
  473. if self.no_registre:
  474. domain = [('national_register_number', '=', self.no_registre)]
  475. contact = partner_obj.search(domain)
  476. if contact:
  477. contact.type = 'representative'
  478. if not contact:
  479. contact_vals = {'name': self.name,
  480. 'firstname': self.firstname,
  481. 'lastname': self.lastname, 'customer': False,
  482. 'is_company': False, 'cooperator': True,
  483. 'street': self.address, 'gender': self.gender,
  484. 'zip': self.zip_code, 'city': self.city,
  485. 'phone': self.phone, 'email': self.email,
  486. 'national_register_number': self.no_registre,
  487. 'country_id': self.country_id.id,
  488. 'out_inv_comm_type': 'bba',
  489. 'out_inv_comm_algorithm': 'random',
  490. 'lang': self.lang,
  491. 'birthdate_date': self.birthdate,
  492. 'parent_id': partner.id,
  493. 'representative': True,
  494. 'function': self.contact_person_function,
  495. 'type': 'representative'}
  496. contact = partner_obj.create(contact_vals)
  497. else:
  498. if len(contact) > 1:
  499. raise UserError(_('There is two different persons with the'
  500. ' same national register number. Please'
  501. ' proceed to a merge before to continue')
  502. )
  503. if contact.parent_id and contact.parent_id.id != partner.id:
  504. raise UserError(_('This contact person is already defined'
  505. ' for another company. Please select'
  506. ' another contact'))
  507. else:
  508. contact.write({'parent_id': partner.id,
  509. 'representative': True})
  510. invoice = self.create_invoice(partner)
  511. self.write({'partner_id': partner.id, 'state': 'done'})
  512. return invoice
  513. @api.one
  514. def block_subscription_request(self):
  515. self.write({'state': 'block'})
  516. @api.one
  517. def unblock_subscription_request(self):
  518. self.write({'state': 'draft'})
  519. @api.one
  520. def cancel_subscription_request(self):
  521. self.write({'state': 'cancelled'})
  522. @api.one
  523. def put_on_waiting_list(self):
  524. self.write({'state': 'waiting'})
  525. class ShareLine(models.Model):
  526. _name = 'share.line'
  527. _description = "Share line"
  528. @api.multi
  529. def _compute_total_line(self):
  530. res = {}
  531. for line in self:
  532. line.total_amount_line = line.share_unit_price * line.share_number
  533. return res
  534. share_product_id = fields.Many2one('product.product',
  535. string='Share type',
  536. required=True,
  537. readonly=True)
  538. share_number = fields.Integer(string='Number of Share',
  539. required=True,
  540. readonly=True)
  541. share_short_name = fields.Char(related='share_product_id.short_name',
  542. string='Share type name',
  543. readonly=True)
  544. share_unit_price = fields.Float(string='Share price',
  545. readonly=True)
  546. effective_date = fields.Date(string='Effective Date',
  547. readonly=True)
  548. partner_id = fields.Many2one('res.partner',
  549. string='Cooperator',
  550. required=True,
  551. ondelete='cascade',
  552. readonly=True)
  553. total_amount_line = fields.Float(compute='_compute_total_line',
  554. string='Total amount line')
  555. class SubscriptionRegister(models.Model):
  556. _name = 'subscription.register'
  557. _description = "Subscription register"
  558. @api.multi
  559. def _compute_total_line(self):
  560. for register_line in self:
  561. register_line.total_amount_line = register_line.share_unit_price * register_line.quantity
  562. name = fields.Char(string='Number Operation',
  563. required=True,
  564. readonly=True)
  565. register_number_operation = fields.Integer(string='Register Number Operation',
  566. required=True,
  567. readonly=True)
  568. partner_id = fields.Many2one('res.partner',
  569. string='Cooperator',
  570. required=True,
  571. readonly=True)
  572. partner_id_to = fields.Many2one('res.partner',
  573. string='Transfered to',
  574. readonly=True)
  575. date = fields.Date(string='Subscription Date',
  576. required=True,
  577. readonly=True)
  578. quantity = fields.Integer(string='Number of share',
  579. readonly=True)
  580. share_unit_price = fields.Float(string='Share price',
  581. readonly=True)
  582. total_amount_line = fields.Float(compute='_compute_total_line',
  583. string='Total amount line')
  584. share_product_id = fields.Many2one('product.product',
  585. string='Share type',
  586. required=True,
  587. readonly=True,
  588. domain=[('is_share', '=', True)])
  589. share_short_name = fields.Char(related='share_product_id.short_name',
  590. string='Share type name',
  591. readonly=True)
  592. share_to_product_id = fields.Many2one('product.product',
  593. string='Share to type',
  594. readonly=True,
  595. domain=[('is_share', '=', True)])
  596. share_to_short_name = fields.Char(related='share_to_product_id.short_name',
  597. string='Share to type name',
  598. readonly=True)
  599. quantity_to = fields.Integer(string='Number of share to',
  600. readonly=True)
  601. share_to_unit_price = fields.Float(string='Share to price',
  602. readonly=True)
  603. type = fields.Selection([('subscription', 'Subscription'),
  604. ('transfer', 'Transfer'),
  605. ('sell_back', 'Sell Back'),
  606. ('convert', 'Conversion')],
  607. string='Operation Type', readonly=True)
  608. company_id = fields.Many2one('res.company', string='Company',
  609. required=True,
  610. change_default=True, readonly=True,
  611. default=lambda self: self.env['res.company']._company_default_get())
  612. user_id = fields.Many2one('res.users',
  613. string='Responsible',
  614. readonly=True,
  615. default=lambda self: self.env.user)
  616. _order = "register_number_operation asc"
  617. @api.model
  618. def read_group(self, domain, fields, groupby, offset=0, limit=None,
  619. orderby=False,
  620. lazy=True):
  621. if 'share_unit_price' in fields:
  622. fields.remove('share_unit_price')
  623. if 'register_number_operation' in fields:
  624. fields.remove('register_number_operation')
  625. res = super(SubscriptionRegister, self).read_group(domain, fields,
  626. groupby,
  627. offset=offset,
  628. limit=limit,
  629. orderby=orderby,
  630. lazy=lazy)
  631. if 'total_amount_line' in fields:
  632. for line in res:
  633. if '__domain' in line:
  634. lines = self.search(line['__domain'])
  635. inv_value = 0.0
  636. for line2 in lines:
  637. inv_value += line2.total_amount_line
  638. line['total_amount_line'] = inv_value
  639. return res