优化表面工艺

This commit is contained in:
jinling.yang
2024-08-07 17:30:29 +08:00
parent 5393ef686a
commit 1547a6064f
6 changed files with 106 additions and 57 deletions

View File

@@ -211,36 +211,46 @@ class RePurchaseOrder(models.Model):
if not line.taxes_id:
raise UserError('请对【产品】中的【税】进行选择')
def get_purchase_order(self, production, product_id_to_production_names):
for pp in production.product_id.model_process_parameters_ids:
def get_purchase_order(self, consecutive_process_parameters, production, product_id_to_production_names):
is_exist = True
server_product_process = []
production_process = product_id_to_production_names.get(
production.product_id.id)
for pp in consecutive_process_parameters:
if pp.gain_way == '外协':
server_product = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', pp.id),
('detailed_type', '=', 'service')])
purchase_order_line = self.env['purchase.order.line'].search(
[('product_id', '=', server_product.id)])
[('product_id', '=', server_product.id), ('product_qty', '=', len(production_process))])
if not purchase_order_line:
is_exist = False
server_product_process.append((0, 0, {
'product_id': server_product.product_variant_id.id,
'product_qty': len(production_process),
'product_uom': server_product.uom_id.id
}))
else:
for item in purchase_order_line:
purchase_order = self.env['purchase.order'].search(
[('state', '=', 'draft'), ('origin', 'ilike', production.name),
('id', '=', item.order_id)])
('id', '=', item.order_id.id)])
if not purchase_order:
is_exist = False
if is_exist is False:
production_process = product_id_to_production_names.get(
production.product_id.id)
self.env['purchase.order'].sudo().create({
'partner_id': server_product.seller_ids.partner_id.id,
'origin': ','.join(production_process),
'state': 'draft',
'order_line': [(0, 0, {
'product_id': server_product.product_variant_id.id,
'product_qty': len(production_process),
'product_uom': server_product.uom_id.id
})]
})
server_product_process.append((0, 0, {
'product_id': server_product.product_variant_id.id,
'product_qty': len(production_process),
'product_uom': server_product.uom_id.id
}))
if is_exist is False:
purchase_order = self.env['purchase.order'].search(
[('state', '=', 'draft'), ('origin', '=', ','.join(production_process))])
if not purchase_order:
self.env['purchase.order'].sudo().create({
'partner_id': server_product.seller_ids.partner_id.id,
'origin': ','.join(production_process),
'state': 'draft',
'order_line': server_product_process})
@api.onchange('order_line')
def _onchange_order_line(self):