콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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



아바타
취소
관련 게시물 답글 화면 활동
1
10월 24
1835
1
10월 22
3417
4
12월 22
9337
V17 Tree, Form view 해결 완료
1
3월 25
1291
0
7월 25
1444