I have the following code where I send by means of onchange and I send
that the value entered in limit is automatically saved in limit_id which
is in class hr.
and I want to do the following before arriving the value entered in limit
to limit_id a subtraction limited minus the amount that contains the
limit_id field of each worker at that moment and show the remaining
amount since each worker can have a value different in limit_id
The way I'm doing it is bad because it only subtracts the first worker and
that result applies to all workers and as I mentioned above I want you to
subtract each worker and show the remaining value depending on the amount
you have in limit_d
someone could help me please
class DiningRoomLimit (models.Model):
_name = 'dining.room.limit'
_order = 'sequence'
name = fields.Char (readonly = True, create = "false", store = True)
limit = fields.Float (string = 'Credit Limit', required = True, digits = (64, 2))
sequence = fields.Integer (required = True, default = 1,)
employee = fields.Many2one ('hr.employee', 'invoice',)
currency_id = fields.Many2one ('res.currency', 'Currency',
default = lambda self: self.env.user.company_id.currency_id.id, required = True)
@ api.onchange ('limit')
def _onchange_limit (self):
for r in self:
result = self.env ['hr.employee']. search ([])
h = r.limit
for record in result:
j = h - record.limit_id
result.write ({
'limit_id': j,
})
hr class
class DiningRoomIndexCord (models.Model):
_inherit = ['hr.employee']
limit_id = fields.Float (string = 'Credit Limit', digits = (64, 2))