Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
1805 Prikazi

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
Opusti
Best Answer

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
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
jul. 19
6663
2
sep. 23
9541
0
mar. 15
4768
2
apr. 21
11261
1
mar. 21
4028