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.

709 lines
32 KiB

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