Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
674 Visualizzazioni

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



Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ott 24
1834
1
ott 22
3412
4
dic 22
9325
1
mar 25
1284
0
lug 25
1436