Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
1878 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
jul. 19
6734
2
sep. 23
9636
0
mrt. 15
4802
2
apr. 21
11370
1
mrt. 21
4095