Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
2066 Visualizzazioni

I have three models wtm.trip, wtm.invoicelist, and wt.invoice

I want to select an invoice from wt.invoice in wtm.invoicelist and update its loading status such as fully loaded or partially loaded.

So, an invoice which is selected as fully loaded can't be selected in another wtm.trip record or this trip more than once.


how should I proceed to solve this problem?

class trip(models.Model):
	_name="wtm.trip"
	trip_number= fields.Char(readonly=True)
	vehicle_id= fields.Many2one('wtm.vehicle', required=True)
	vehicle_vendor= fields.Many2one(related='vehicle_id.vendor_id')
	​​invoice_line_ids= fields.One2many('wtm.invoicelist', 'invoiceline_id')

class invoicelist(models.Model):
​_name="wtm.invoicelist"

​invoiceline_id= fields.Many2one('wtm.trip', string='Invoice Number')
​invoice_id= fields.Many2one('wtm.invoice',string="Invoice Number")
​invoice_date= fields.Datetime(related='info_id.invoice_date',readonly=True)
​loading_status= fields.Selection([('full','Fully Loaded'),('partial','Partially Loaded')], default='full')user_name= fields.Many2one('res.users',readonly=True, default=lambdaself: self.env.user)num_of_carton= fields.Char(related='info_id.number_of_carton') class invoice(models.Model):
​_name="wtm.invoice"

​invoice_number= fields.Char()
​invoice_date= fields.Datetime()
​invoice_value= fields.Float()


Avatar
Abbandona
Risposta migliore

1. Create a boolean inside invoice model as selected_once.

2. Once you set some invoice status to fully_loaded or partially_loaded set that perticular invoice field selected_once to True.

3. Now apply domain for invoice ids to be visible which evaluates selected_once to False.

This will show only invoices having selected_once set to False inside dropdown. Else you can add api.constrains and validate over same boolean and return validation error like 


"invoice which is selected as fully loaded can't be selected in another wtm.trip record or this trip more than once."


Upvote if it helps.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
lug 19
6995
2
set 23
9856
0
mar 15
4937
2
apr 21
11511
1
mar 21
4338