跳至内容
菜单
此问题已终结
1 回复
1856 查看

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()


形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
1
7月 19
6720
2
9月 23
9623
0
3月 15
4799
2
4月 21
11355
1
3月 21
4077