0

I need your advice to populate field barcode in model employee with concatenation of field location_number in model work_location_id and sequence generated by automated action in odoo 15 ?

I want to automatically generate in the number field an identifier with this particular formatting (such as XX-YYYY-AAAAAAA) where XX is generated from the number assigned to location of taking office of the employee since it is a company with several sites, YYYY is generated from the current year and AAAAAAA is generated from the number of files created

What did I do wrong in my code below ?

if not record.barcode:

  XX = env['work.location.id'].get('location.number')
  YYYY_AAAAAAA = env['ir.sequence'].next_by_code('matricule_')

  record.write({
  'barcode': XX + YYYY_AAAAAAA,
  })

I need to add location_number as prefix of the sequence...instead of XX

Kikoun
  • 1
  • 1
  • There is something wrong in your way to get one record of env['work.location.id']. You should use self.env['work.location.id'].browse(your_id) or self.env['work.location.id'].search([('one_of_location_fields','=','your_value')]) instead – sylvain Mar 17 '22 at 20:49

1 Answers1

0

To make it easy : consider using the odoo tools to create a computed field. You can find it this way : in App Settings, switch to debug mode by adding "?debug=1" in your url, reload the page, then go to the new Technical Menu-tab > Fields.

enter image description here

Then click on the "Create" button. And you can create your own computed field (type: Char, in your case). As example :

enter image description here

sylvain
  • 853
  • 1
  • 7
  • 20