Skip to Content
Menu
This question has been flagged
1 Reply
4360 Views

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',

})

Avatar
Discard
Author Best Answer

solved by me after so much thinking..

with one button.

we place a bonus to the employee, then subtract the total amount of each invoce less bonus from the employee to whom the invoice belongs.

we perform the subtraction if the bonus is less than the total oh the invoice, if it is less and if it is greater.

and the invoice the is paid goes to this payment

class DiningRoomDiscount(models.Model):

_name = 'dining.room.discount'

prueba = fields.Integer(string='Base imponible', )

worker = fields.Many2one('hr.employee', 'Ficha del Trabajador:',)

fact_id = fields.Many2one('dining.room.invoice', 'factura',)

bond_id = fields.Many2one('dining.room.configuration.bond', 'bono',)

invoice_id = fields.Many2one('dining.room.invoice', 'invoice',)

ficha = fields.Char(string='ficha', )

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.bond

worker = r.worker.name

## SEND BONUS TO EACH EMPLOYEE ##

result = self.env['hr.employee'].search([])

result.write({

'discount_id': bond,

})

## IF THE BONUS IS EQUAL TO THE TOTAL ##

result_same = self.env['dining.room.invoice'].search([('state','ilike','credit'),('amount_total', '=', bond)])

for h in result_same:

for o in h.worker:

resultado = o.discount_id - h.amount_total

result_worker = self.env['hr.employee'].search([('name', '=', o.name)])

for worker in result_worker:

worker.write({

'discount_id': resultado,

})

h.write({

'surplus': resultado,

'state': 'paymet',

})

## IF THE BONUS IS LESS TO THE TOTAL ##

result_less = self.env['dining.room.invoice'].search([('state','ilike','credit'),('amount_total', '<', bond)])

for h in result_less:

for o in h.worker:

resultado = o.discount_id - h.amount_total

result_worker_less = self.env['hr.employee'].search([('name', '=', o.name)])

for worker in result_worker_less:

worker.write({

'discount_id': resultado,

})

h.write({

'state': 'paymet',

'surplus': resultado,

})

## IF THE GREATER IS EQUAL TO THE TOTAL ##

result_higher = self.env['dining.room.invoice'].search([('state','ilike','credit'),('amount_total', '>', bond)])

for h in result_higher:

for o in h.worker:

resultado = h.amount_total - o.discount_id

result_worker_higher = self.env['hr.employee'].search([('name', '=', o.name)])

for worker in result_worker_higher:

worker.write({

'discount_id': resultado,

})

h.write({

'surplus': resultado,

})

Avatar
Discard