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,14 +92,15 @@ class PurchaseOrder(models.Model):
return True
return False
@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
"""Override create to handle linking with inventory moves if provided"""
# Extract subcontracting moves from vals if they exist
subcontracting_move_ids = vals.get('subcontracting_move_ids')
# Create the purchase orders first using the parent method
orders = super().create(vals_list)
# Create the purchase order first
purchase_order = super().create(vals)
# Process subcontracting moves linking for each created order
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_move_ids:
@ -108,13 +109,13 @@ class PurchaseOrder(models.Model):
if command[0] == 6: # Replace all
move_ids = command[2]
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
move_id = command[1]
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):
"""Override write to handle linking/unlinking of inventory moves"""

View File

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