fix some bug regarding the groups in xml view

This commit is contained in:
admin.suherdy 2025-11-20 08:49:19 +07:00
parent 3697d7f785
commit c92a3b0291
13 changed files with 485 additions and 486 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -92,29 +92,30 @@ class PurchaseOrder(models.Model):
return True return True
return False return False
@api.model @api.model_create_multi
def create(self, vals): def create(self, vals_list):
"""Override create to handle linking with inventory moves if provided""" """Override create to handle linking with inventory moves if provided"""
# Extract subcontracting moves from vals if they exist # Create the purchase orders first using the parent method
subcontracting_move_ids = vals.get('subcontracting_move_ids') orders = super().create(vals_list)
# Create the purchase order first # Process subcontracting moves linking for each created order
purchase_order = super().create(vals) for order, vals in zip(orders, vals_list):
subcontracting_move_ids = vals.get('subcontracting_move_ids')
# If subcontracting moves were provided, link them # If subcontracting moves were provided, link them
if subcontracting_move_ids: if subcontracting_move_ids:
# Process the commands in the Many2many field # Process the commands in the Many2many field
for command in subcontracting_move_ids: for command in subcontracting_move_ids:
if command[0] == 6: # Replace all if command[0] == 6: # Replace all
move_ids = command[2] move_ids = command[2]
moves = self.env['stock.move'].browse(move_ids) moves = self.env['stock.move'].browse(move_ids)
moves.write({'purchase_order_id': purchase_order.id}) moves.write({'purchase_order_id': order.id})
elif command[0] == 4: # Add one elif command[0] == 4: # Add one
move_id = command[1] move_id = command[1]
move = self.env['stock.move'].browse(move_id) move = self.env['stock.move'].browse(move_id)
move.write({'purchase_order_id': purchase_order.id}) move.write({'purchase_order_id': order.id})
return purchase_order return orders
def write(self, vals): def write(self, vals):
"""Override write to handle linking/unlinking of inventory moves""" """Override write to handle linking/unlinking of inventory moves"""

View File

@ -24,11 +24,9 @@
<field name="model">stock.move</field> <field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_tree"/> <field name="inherit_id" ref="stock.view_move_tree"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="product_uom_qty" position="after"> <xpath expr="//field[@name='product_uom_qty']" position="after">
<field name="purchase_order_id" <field name="purchase_order_id" invisible="not is_subcontract"/>
invisible="not is_subcontract" </xpath>
groups="purchase.group_purchase_user"/>
</field>
</field> </field>
</record> </record>