Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
1903 Ansichten

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
Verwerfen
Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Juli 19
6754
2
Sept. 23
9664
0
März 15
4808
2
Apr. 21
11383
1
März 21
4113