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.

697 lines
33 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime
  3. from openerp import api, fields, models, _
  4. from openerp.addons.base_iban import base_iban
  5. from openerp.exceptions import UserError, ValidationError
  6. _REQUIRED = ['email',
  7. 'firstname',
  8. 'lastname',
  9. 'birthdate',
  10. 'address',
  11. 'share_product_id',
  12. 'ordered_parts',
  13. 'zip_code',
  14. 'city',
  15. 'iban',
  16. 'no_registre',
  17. 'data_policy_approved',
  18. 'gender'] # Could be improved including required from model
  19. @api.model
  20. def _lang_get(self):
  21. languages = self.env['res.lang'].search([])
  22. return [(language.code, language.name) for language in languages]
  23. class subscription_request(models.Model):
  24. _name = 'subscription.request'
  25. _description = 'Subscription Request'
  26. def get_required_field(self):
  27. return _REQUIRED
  28. @api.model
  29. def create(self, vals):
  30. partner_obj = self.env['res.partner']
  31. if not vals.get('partner_id'):
  32. cooperator = False
  33. if vals.get('no_registre'):
  34. cooperator = partner_obj.get_cooperator_from_nin(
  35. vals.get('no_registre'))
  36. if cooperator:
  37. # TODO remove the following line of code once it has
  38. # been founded a way to avoid dubble entry
  39. cooperator = cooperator[0]
  40. if cooperator.member:
  41. vals['type'] = 'increase'
  42. vals['already_cooperator'] = True
  43. else:
  44. vals['type'] = 'subscription'
  45. vals['partner_id'] = cooperator.id
  46. if not cooperator.cooperator:
  47. cooperator.write({'cooperator': True})
  48. else:
  49. cooperator_id = vals.get('partner_id')
  50. cooperator = partner_obj.browse(cooperator_id)
  51. if cooperator.member:
  52. vals['type'] = 'increase'
  53. vals['already_cooperator'] = True
  54. subscr_request = super(subscription_request, self).create(vals)
  55. confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation', False)
  56. confirmation_mail_template.send_mail(subscr_request.id)
  57. return subscr_request
  58. @api.model
  59. def create_comp_sub_req(self, vals):
  60. vals["name"] = vals['company_name']
  61. if not vals.get('partner_id'):
  62. cooperator = self.env['res.partner'].get_cooperator_from_crn(vals.get('company_register_number'))
  63. if cooperator:
  64. vals['partner_id'] = cooperator.id
  65. vals['type'] = 'increase'
  66. vals['already_cooperator'] = True
  67. subscr_request = super(subscription_request, self).create(vals)
  68. confirmation_mail_template = self.env.ref('easy_my_coop.email_template_confirmation_company', False)
  69. confirmation_mail_template.send_mail(subscr_request.id, True)
  70. return subscr_request
  71. def check_belgian_identification_id(self, nat_register_num):
  72. if not self.check_empty_string(nat_register_num):
  73. return False
  74. if len(nat_register_num) != 11:
  75. return False
  76. if not nat_register_num.isdigit():
  77. return False
  78. birthday_number = nat_register_num[0:9]
  79. controle = nat_register_num[9:11]
  80. check_controle = 97 - (int(birthday_number) % 97)
  81. if int(check_controle) != int(controle):
  82. check_controle = 97 - ((2000000000 + int(birthday_number)) % 97)
  83. if int(check_controle) != int(controle):
  84. return False
  85. return True
  86. def check_empty_string(self, value):
  87. if value is None or value is False or value == '':
  88. return False
  89. return True
  90. def check_iban(self, iban):
  91. validated = True
  92. try:
  93. base_iban.validate_iban(iban)
  94. except ValidationError:
  95. validated = False
  96. return validated
  97. @api.multi
  98. @api.depends('iban', 'no_registre', '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. if validated and (sub_request.skip_control_ng or
  103. self.check_belgian_identification_id(
  104. sub_request.no_registre)):
  105. validated = True
  106. else:
  107. validated = False
  108. sub_request.validated = validated
  109. @api.multi
  110. @api.depends('share_product_id',
  111. 'share_product_id.list_price',
  112. 'ordered_parts')
  113. def _compute_subscription_amount(self):
  114. for sub_request in self:
  115. sub_request.subscription_amount = (sub_request.share_product_id.
  116. list_price *
  117. sub_request.ordered_parts)
  118. already_cooperator = fields.Boolean(string="I'm already cooperator",
  119. readonly=True,
  120. states={'draft': [('readonly', False)]}
  121. )
  122. name = fields.Char(string='Name',
  123. required=True,
  124. readonly=True,
  125. states={'draft': [('readonly', False)]})
  126. firstname = fields.Char(string='Firstname',
  127. readonly=True,
  128. states={'draft': [('readonly', False)]})
  129. lastname = fields.Char(string='Lastname',
  130. readonly=True,
  131. states={'draft': [('readonly', False)]})
  132. birthdate = fields.Date(string="Birthdate",
  133. readonly=True,
  134. states={'draft': [('readonly', False)]})
  135. gender = fields.Selection([('male', _('Male')),
  136. ('female', _('Female')),
  137. ('other', _('Other'))],
  138. string='Gender',
  139. readonly=True,
  140. states={'draft': [('readonly', False)]})
  141. type = fields.Selection([('new', 'New Cooperator'),
  142. ('subscription', 'Subscription'),
  143. ('increase', 'Increase number of share')],
  144. string='Type', default="new",
  145. readonly=True,
  146. states={'draft': [('readonly', False)]})
  147. state = fields.Selection([('draft', 'Draft'),
  148. ('block', 'Blocked'),
  149. ('done', 'Done'),
  150. ('waiting', 'Waiting'),
  151. ('transfer', 'Transfer'),
  152. ('cancelled', 'Cancelled'),
  153. ('paid', 'paid')],
  154. string='State', required=True, default="draft")
  155. email = fields.Char(string='Email',
  156. required=True,
  157. readonly=True,
  158. states={'draft': [('readonly', False)]})
  159. iban = fields.Char(string='Account Number',
  160. readonly=True,
  161. states={'draft': [('readonly', False)]})
  162. partner_id = fields.Many2one('res.partner',
  163. string='Cooperator',
  164. readonly=True,
  165. states={'draft': [('readonly', False)]})
  166. share_product_id = fields.Many2one('product.product',
  167. string='Share type',
  168. domain=[('is_share', '=', True)],
  169. required=True,
  170. readonly=True,
  171. states={'draft': [('readonly', False)]})
  172. share_short_name = fields.Char(related='share_product_id.short_name',
  173. string='Share type name',
  174. readonly=True,
  175. states={'draft': [('readonly', False)]})
  176. share_unit_price = fields.Float(related='share_product_id.list_price',
  177. string='Share price',
  178. readonly=True,
  179. states={'draft': [('readonly', False)]})
  180. subscription_amount = fields.Float(compute='_compute_subscription_amount',
  181. string='Subscription amount',
  182. readonly=True,
  183. states={'draft': [('readonly', False)]})
  184. ordered_parts = fields.Integer(string='Number of Share',
  185. required=True,
  186. readonly=True,
  187. default=1,
  188. states={'draft': [('readonly', False)]})
  189. address = fields.Char(string='Address',
  190. required=True,
  191. readonly=True,
  192. states={'draft': [('readonly', False)]})
  193. city = fields.Char(string='City',
  194. required=True,
  195. readonly=True,
  196. states={'draft': [('readonly', False)]})
  197. zip_code = fields.Char(string='Zip Code',
  198. required=True,
  199. readonly=True,
  200. states={'draft': [('readonly', False)]})
  201. country_id = fields.Many2one('res.country',
  202. string='Country',
  203. ondelete='restrict',
  204. required=True,
  205. readonly=True,
  206. states={'draft': [('readonly', False)]})
  207. phone = fields.Char(string='Phone',
  208. readonly=True,
  209. states={'draft': [('readonly', False)]})
  210. no_registre = fields.Char(string='National Register Number',
  211. readonly=True,
  212. states={'draft': [('readonly', False)]})
  213. user_id = fields.Many2one('res.users',
  214. string='Responsible',
  215. readonly=True)
  216. validated = fields.Boolean(compute='_validated_lines',
  217. string='Valid Line?',
  218. readonly=True)
  219. skip_control_ng = fields.Boolean(string="Skip control",
  220. help="if this field is checked then no"
  221. " control will be done on the national"
  222. " register number and on the iban bank"
  223. " account. To be done in case of the id"
  224. " card is from abroad or in case of"
  225. " a passport")
  226. lang = fields.Selection(_lang_get,
  227. string='Language',
  228. required=True,
  229. readonly=True,
  230. states={'draft': [('readonly', False)]},
  231. default=lambda self: self.env['res.company']._company_default_get().default_lang_id.code)
  232. date = fields.Date(string='Subscription date request',
  233. required=True,
  234. readonly=True,
  235. states={'draft': [('readonly', False)]},
  236. default=lambda self: datetime.strftime(datetime.now(),
  237. '%Y-%m-%d'))
  238. company_id = fields.Many2one('res.company',
  239. string='Company',
  240. required=True,
  241. change_default=True,
  242. readonly=True,
  243. default=lambda self: self.env['res.company']._company_default_get())
  244. is_company = fields.Boolean(string='Is a company',
  245. readonly=True,
  246. states={'draft': [('readonly', False)]})
  247. is_operation = fields.Boolean(string='Is an operation',
  248. readonly=True,
  249. states={'draft': [('readonly', False)]})
  250. company_name = fields.Char(string="Company name",
  251. readonly=True,
  252. states={'draft': [('readonly', False)]})
  253. company_email = fields.Char(string="Company email",
  254. readonly=True,
  255. states={'draft': [('readonly', False)]})
  256. company_register_number = fields.Char(string='Company register number',
  257. readonly=True,
  258. states={'draft': [('readonly', False)]})
  259. company_type = fields.Selection([('scrl', 'SCRL'),
  260. ('asbl', 'ASBL'),
  261. ('sprl', 'SPRL'),
  262. ('sa', 'SA'),
  263. ('other', 'Other')],
  264. string="Company type",
  265. readonly=True,
  266. states={'draft': [('readonly', False)]})
  267. same_address = fields.Boolean(string='Same address',
  268. readonly=True,
  269. states={'draft': [('readonly', False)]})
  270. activities_address = fields.Char(string='Activities address',
  271. readonly=True,
  272. states={'draft': [('readonly', False)]})
  273. activities_city = fields.Char(string='Activities city',
  274. readonly=True,
  275. states={'draft': [('readonly', False)]})
  276. activities_zip_code = fields.Char(string='Activities zip Code',
  277. readonly=True,
  278. states={'draft': [('readonly', False)]})
  279. activities_country_id = fields.Many2one('res.country',
  280. string='Activities country',
  281. ondelete='restrict',
  282. readonly=True,
  283. states={'draft': [('readonly', False)]})
  284. contact_person_function = fields.Char(string='Function',
  285. readonly=True,
  286. states={'draft': [('readonly', False)]})
  287. operation_request_id = fields.Many2one('operation.request',
  288. string="Operation Request",
  289. readonly=True,
  290. states={'draft': [('readonly', False)]})
  291. capital_release_request = fields.One2many('account.invoice',
  292. 'subscription_request',
  293. string='Capital release request',
  294. readonly=True,
  295. states={'draft': [('readonly', False)]})
  296. capital_release_request_date = fields.Date(string="Force the capital "
  297. "release request date",
  298. help="Keep empty to use the "
  299. "current date",
  300. copy=False,
  301. readonly=True,
  302. states={'draft': [('readonly', False)]})
  303. source = fields.Selection([('website', 'Website'),
  304. ('crm', 'CRM'),
  305. ('manual', 'Manual'),
  306. ('operation', 'Operation')],
  307. string="Source",
  308. default="website",
  309. readonly=True,
  310. states={'draft': [('readonly', False)]})
  311. data_policy_approved = fields.Boolean(
  312. string='Data Policy Approved',
  313. default=False,
  314. # required=True,
  315. )
  316. _order = "id desc"
  317. def get_person_info(self, partner):
  318. self.firstname = partner.firstname
  319. self.name = partner.name
  320. self.lastname = partner.lastname
  321. self.no_registre = partner.national_register_number
  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. invoice_email_template = self.env['mail.template'].search([('name', '=', 'Request to Release Capital - Send by Email')])[0]
  375. # we send the email with the capital release request in attachment
  376. invoice_email_template.send_mail(invoice.id, True)
  377. invoice.sent = True
  378. def create_invoice(self, partner):
  379. # get subscription journal
  380. journal = self.env['account.journal'].search([('code', '=', 'SUBJ')])[0]
  381. # get the account for associate
  382. # TODO this should be defined in configuration
  383. if self.company_id.property_cooperator_account:
  384. account = self.company_id.property_cooperator_account
  385. else:
  386. account = self.env['account.account'].search([('code', '=', '416000')])[0]
  387. # creating invoice and invoice lines
  388. invoice_vals = {'partner_id': partner.id,
  389. 'journal_id': journal.id,
  390. 'account_id': account.id,
  391. 'type': 'out_invoice',
  392. 'release_capital_request': True,
  393. 'subscription_request': self.id}
  394. if self.capital_release_request_date:
  395. invoice_vals['date_invoice'] = self.capital_release_request_date
  396. invoice = self.env['account.invoice'].create(invoice_vals)
  397. vals = self._prepare_invoice_line(self.share_product_id, partner,
  398. self.ordered_parts)
  399. vals['invoice_id'] = invoice.id
  400. self.env['account.invoice.line'].create(vals)
  401. # validate the capital release request
  402. invoice.signal_workflow('invoice_open')
  403. self.send_capital_release_request(invoice)
  404. return invoice
  405. def get_partner_company_vals(self):
  406. partner_vals = {'name': self.company_name,
  407. 'last_name': self.company_name,
  408. 'is_company': self.is_company,
  409. 'company_register_number': self.company_register_number, #noqa
  410. 'customer': False, 'cooperator': True,
  411. 'street': self.address, 'zip': self.zip_code,
  412. 'city': self.city, 'email': self.company_email,
  413. 'out_inv_comm_type': 'bba',
  414. 'customer': self.share_product_id.customer,
  415. 'out_inv_comm_algorithm': 'random',
  416. 'country_id': self.country_id.id,
  417. 'lang': self.lang}
  418. return partner_vals
  419. def get_partner_vals(self):
  420. partner_vals = {'name': self.name, 'firstname': self.firstname,
  421. 'lastname': self.lastname, 'street': self.address,
  422. 'zip': self.zip_code, 'email': self.email,
  423. 'gender': self.gender, 'cooperator': True,
  424. 'city': self.city, 'phone': self.phone,
  425. 'national_register_number': self.no_registre,
  426. 'out_inv_comm_type': 'bba',
  427. 'out_inv_comm_algorithm': 'random',
  428. 'country_id': self.country_id.id, 'lang': self.lang,
  429. 'birthdate_date': self.birthdate,
  430. 'customer': self.share_product_id.customer}
  431. return partner_vals
  432. def create_coop_partner(self):
  433. partner_obj = self.env['res.partner']
  434. if self.is_company:
  435. partner_vals = self.get_partner_company_vals()
  436. else:
  437. partner_vals = self.get_partner_vals()
  438. partner = partner_obj.create(partner_vals)
  439. if self.iban:
  440. self.env['res.partner.bank'].create({
  441. 'partner_id': partner.id,
  442. 'acc_number': self.iban
  443. })
  444. return partner
  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.no_registre:
  463. domain = [('national_register_number', '=', self.no_registre)]
  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.no_registre:
  473. domain = [('national_register_number', '=', self.no_registre)]
  474. contact = partner_obj.search(domain)
  475. if contact:
  476. contact.type = 'representative'
  477. if not contact:
  478. contact_vals = {'name': self.name,
  479. 'firstname': self.firstname,
  480. 'lastname': self.lastname, 'customer': False,
  481. 'is_company': False, 'cooperator': True,
  482. 'street': self.address, 'gender': self.gender,
  483. 'zip': self.zip_code, 'city': self.city,
  484. 'phone': self.phone, 'email': self.email,
  485. 'national_register_number': self.no_registre,
  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. contact = partner_obj.create(contact_vals)
  496. else:
  497. if len(contact) > 1:
  498. raise UserError(_('There is two different persons with the'
  499. ' same national register number. Please'
  500. ' proceed to a merge before to continue')
  501. )
  502. if contact.parent_id and contact.parent_id.id != partner.id:
  503. raise UserError(_('This contact person is already defined'
  504. ' for another company. Please select'
  505. ' another contact'))
  506. else:
  507. contact.write({'parent_id': partner.id,
  508. 'representative': True})
  509. invoice = self.create_invoice(partner)
  510. self.write({'partner_id': partner.id, 'state': 'done'})
  511. return invoice
  512. @api.one
  513. def block_subscription_request(self):
  514. self.write({'state': 'block'})
  515. @api.one
  516. def unblock_subscription_request(self):
  517. self.write({'state': 'draft'})
  518. @api.one
  519. def cancel_subscription_request(self):
  520. self.write({'state': 'cancelled'})
  521. @api.one
  522. def put_on_waiting_list(self):
  523. self.write({'state': 'waiting'})
  524. class share_line(models.Model):
  525. _name = 'share.line'
  526. @api.multi
  527. def _compute_total_line(self):
  528. res = {}
  529. for line in self:
  530. line.total_amount_line = line.share_unit_price * line.share_number
  531. return res
  532. share_product_id = fields.Many2one('product.product',
  533. string='Share type',
  534. required=True,
  535. readonly=True)
  536. share_number = fields.Integer(string='Number of Share',
  537. required=True,
  538. readonly=True)
  539. share_short_name = fields.Char(related='share_product_id.short_name',
  540. string='Share type name',
  541. readonly=True)
  542. share_unit_price = fields.Float(string='Share price',
  543. readonly=True)
  544. effective_date = fields.Date(string='Effective Date',
  545. readonly=True)
  546. partner_id = fields.Many2one('res.partner',
  547. string='Cooperator',
  548. required=True,
  549. ondelete='cascade',
  550. readonly=True)
  551. total_amount_line = fields.Float(compute='_compute_total_line',
  552. string='Total amount line')
  553. class subscription_register(models.Model):
  554. _name = 'subscription.register'
  555. @api.multi
  556. def _compute_total_line(self):
  557. for register_line in self:
  558. register_line.total_amount_line = register_line.share_unit_price * register_line.quantity
  559. name = fields.Char(string='Register Number Operation',
  560. required=True,
  561. readonly=True)
  562. register_number_operation = fields.Integer(string='Register Number Operation',
  563. required=True,
  564. readonly=True)
  565. partner_id = fields.Many2one('res.partner',
  566. string='Cooperator',
  567. required=True,
  568. readonly=True)
  569. partner_id_to = fields.Many2one('res.partner',
  570. string='Transfered to',
  571. readonly=True)
  572. date = fields.Date(string='Subscription Date',
  573. required=True,
  574. readonly=True)
  575. quantity = fields.Integer(string='Number of share',
  576. readonly=True)
  577. share_unit_price = fields.Float(string='Share price',
  578. readonly=True)
  579. total_amount_line = fields.Float(compute='_compute_total_line',
  580. string='Total amount line')
  581. share_product_id = fields.Many2one('product.product',
  582. string='Share type',
  583. required=True,
  584. readonly=True,
  585. domain=[('is_share', '=', True)])
  586. share_short_name = fields.Char(related='share_product_id.short_name',
  587. string='Share type name',
  588. readonly=True)
  589. share_to_product_id = fields.Many2one('product.product',
  590. string='Share to type',
  591. readonly=True,
  592. domain=[('is_share', '=', True)])
  593. share_to_short_name = fields.Char(related='share_to_product_id.short_name',
  594. string='Share to type name',
  595. readonly=True)
  596. quantity_to = fields.Integer(string='Number of share to',
  597. readonly=True)
  598. share_to_unit_price = fields.Float(string='Share to price',
  599. readonly=True)
  600. type = fields.Selection([('subscription', 'Subscription'),
  601. ('transfer', 'Transfer'),
  602. ('sell_back', 'Sell Back'),
  603. ('convert', 'Conversion')],
  604. string='Operation Type', readonly=True)
  605. company_id = fields.Many2one('res.company', string='Company',
  606. required=True,
  607. change_default=True, readonly=True,
  608. default=lambda self: self.env['res.company']._company_default_get())
  609. user_id = fields.Many2one('res.users',
  610. string='Responsible',
  611. readonly=True,
  612. default=lambda self: self.env.user)
  613. _order = "register_number_operation asc"
  614. @api.model
  615. def read_group(self, domain, fields, groupby, offset=0, limit=None,
  616. orderby=False,
  617. lazy=True):
  618. if 'share_unit_price' in fields:
  619. fields.remove('share_unit_price')
  620. if 'register_number_operation' in fields:
  621. fields.remove('register_number_operation')
  622. res = super(subscription_register, self).read_group(domain, fields,
  623. groupby,
  624. offset=offset,
  625. limit=limit,
  626. orderby=orderby,
  627. lazy=lazy)
  628. if 'total_amount_line' in fields:
  629. for line in res:
  630. if '__domain' in line:
  631. lines = self.search(line['__domain'])
  632. inv_value = 0.0
  633. for line2 in lines:
  634. inv_value += line2.total_amount_line
  635. line['total_amount_line'] = inv_value
  636. return res