I wish to do the following
I have a class invoice, I have an inheritance to hr.employee and I have another class called discount
I do the following recorded several invoices to ones employees with credit status
now from the discunt class I want to take a tour and krow which invoices each employee must then make a subtraction to the amount that will be deducted from all the employees minus each of the structures the invoice you owe, if the invoice is the amount of an invoice is equal to the discount pass the payment status and leave the other invoices in credit status, if the amount of the invoice is greater than reacts the subtraction and shows the remaining total, if the amount of the invoice is less than the send a paid status and the remaining total of the discount is subtracted to another contract.
this is my class invoice
class DiningRoom(models.Model):
_name = 'dining.room.invoice'
_order = 'create_date desc'
_rec_name = 'number_invoice'
number_invoice = fields.Char(default=lambda self: _('New'), required=True, string='Nro. de Factura')
amount_untaxed = fields.Float(string='Base imponible', readonly=True, track_visibility='always', compute='_amount_all', store=True, digits=(64, 2))
amount_total = fields.Float(string='Total', readonly=True, track_visibility='always', compute='_amount_all', store=True, digits=(64, 2))
reference = fields.Char(string='Referencia Bancaria:',)
worker = fields.Many2one('hr.employee', 'Ficha del Trabajador:')
client = fields.Many2one('dining.room.client', 'Cedula del Cliente:')
currency_id = fields.Many2one('res.currency', 'Currency',
default=lambda self: self.env.user.company_id.currency_id.id, required=True)
product_id = fields.Many2one('dining.products', related='product_ids.product_id', string='Comida')
product_ids = fields.One2many('dining.room.order', 'order_id', string='Productos', required=True, copy=True, store=True)
state = fields.Selection([
('draft', 'Borrador'),
('credit', 'Credito'),
('transfer', 'Tranferencia'),
('cash', 'Efectivo'),
('cancel', 'Anular'),
('paymet', 'Pago'),
], string=_('Status'), readonly=True, copy=False, index=True, default='draft',)
model_room = fields.Selection([
('credit', "Credito"),
('transfer', "Transferencia"),
('cash', "Efectivo"),
],string="Pago", required=True, default='credit')
date = fields.Datetime(string='Fecha', default=fields.Datetime.now)
date2 = fields.Date(string='Fecha')
option = fields.Selection([
('worker','trabajador'),
('client','cliente')
],string="opcion", required=True, default='worker')
prueba = fields.Float(string='Base imponible', digits=(64, 2))
this is my class discount
class DiningRoomDiscount(models.Model):
_name = 'dining.room.discount'
bond_id = fields.Many2one('dining.room.configuration.bond', 'bono',)
currency_id = fields.Many2one('res.currency', 'Currency',
default=lambda self: self.env.user.company_id.currency_id.id, required=True)
@api.multi
def discount_method(self):
for r in self:
bond = r.bond_id.vat
worker = r.worker.name
result = self.env['dining.room.invoice'].search([('state','ilike','credit'),('amount_total', '>=', bond)])
return result.write({
'state': 'paymet',
})