Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ

Here is a code snippet of the model. There is the direction, shipper and consignee.

class FreightShipment(models.Model): 
    _name = 'freight.shipment'
   ...
   direction = fields.Selection(([('import', 'Import'), ('export', 'Export')]), string= 'Direction')
   shipper_id = fields.Many2one('res.partner', 'Shipper',
                                 domain=[('shipper', '=', True)])
   consignee_id = fields.Many2one('res.partner', 'Consignee',
                                   domain=[('consignee', '=', True)])

In the form/view. If the direction is 'Export', the values for the Shipper dropdown should all be coming from the 'PHILIPPINES', likewise for the Consignee, the values for the dropdown should all be from countries not from the Philippines.

Here is the code snippet in the view.

<div class="oe_title mb24"> 
   <h1>
      <field class="text-break" name="name" default_focus="1" readonly="1"/>
   </h1>
   <h3>
      <field name=" direction" widget="radio" required="1" options="{'horizontal': true}"/>
   </h3>
</div>
...
<group>
    <group string="Transporter">
        <field name ="shipper_id" required="1"/>
        <span class="o_form_label o_td_label" name="address_name">
           <b></b>
        </span>
        <div class="o_address_format">
           <field name="shipper_phone" widget="phone"/>
           <field name="shipper_email" widget= "email"/>
        </div>
        <field name="shipper_identifier"/>
    </group>
    <group string="Customer">
        <field name="consignee_id" required="1"/>
        <span class="o_form_label o_td_label" name="address_name">
           <b></b>
        </span>
        <div class="o_address_format">
           <field name="consignee_phone" widget="phone"/>
           <field name="consignee_email" widget="email"/>
        </div>
        <field name="consignee_identifier"/>
    </group >
</group>

Using Co-Pilot, it generated a function when the direction has a value of 'Export' it will get the new value but it did not work.

@api.onchange('direction') 
def _onchange_direction(self):
   if self.direction == 'export':
      return {
         'domain': {
            'shipper_id': [('shipper', '=', True), ( 'country_id.name', '=', 'PHILIPPINES')],
            'consignee_id': [('consignee', '=', True), ('country_id.name', '!=', 'PHILIPPINES'],
          }
      }
   else:
       return {
           'domain': {
               'shipper_id': [('shipper', '=', True)],
                'consignee_id': [('consignee', '=', True )],
            }
        }
       


Also is my condition for the filter right? How could I try to check if the Shipper or Consignee is from or not in the Philippines. How can I check the database? What table should I use? I also Odoo.sh



Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 24
1834
1
thg 10 22
3403
4
thg 12 22
9319
V17 Tree, Form view Đã xử lý
1
thg 3 25
1279
0
thg 7 25
1429