表面工艺类别拖动排序

This commit is contained in:
jinling.yang
2023-03-29 17:48:03 +08:00
parent 93c9287717
commit 20d9e469f5
7 changed files with 147 additions and 99 deletions

View File

@@ -229,85 +229,86 @@ class ProductionLot(models.Model):
return "%s-%03d" % (product.name, 1)
# class ResPurchaseOrder(models.Model):
# _inherit = 'purchase.order'
#
# # def button_approve(self, force=False):
# # result = super().button_approve(force=force)
# # self._create_picking_RES()
# # return result
#
# # @api.depends('order_line.move_ids')
# # def _compute_subcontracting_resupply_picking_count(self):
# # for purchase in self:
# # purchase.subcontracting_resupply_picking_count = len(purchase._get_subcontracting_resupplies_new())
# #
# # def _get_subcontracting_resupplies_new(self):
# # moves_subcontracted = self.order_line.move_ids.filtered(lambda m: m.is_subcontract)
# # # subcontracted_productions = moves_subcontracted.move_orig_ids.production_id
# # return moves_subcontracted.picking_id
#
# def _prepare_picking_RES(self):
# if not self.group_id:
# self.group_id = self.group_id.create({
# 'name': self.name,
# 'partner_id': self.partner_id.id
# })
# if not self.partner_id.property_stock_supplier.id:
# raise UserError(_("You must set a Vendor Location for this partner %s", self.partner_id.name))
# picking_type_id_res = self.env['stock.picking.type'].search(
# [('sequence_code', '=', 'RES'), ('barcode', '=', 'WH-RESUPPLY')])
# return {
# 'picking_type_id': picking_type_id_res.id if picking_type_id_res else self.picking_type_id.id,
# 'partner_id': self.partner_id.id,
# 'user_id': False,
# 'date': self.date_order,
# 'origin': self.name,
# 'location_dest_id': self._get_destination_location(),
# 'location_id': self.partner_id.property_stock_supplier.id,
# 'company_id': self.company_id.id,
# }
#
# def _create_picking(self):
# StockPicking = self.env['stock.picking']
# for order in self.filtered(lambda po: po.state in ('purchase', 'done')):
# if any(product.type in ['product', 'consu'] for product in order.order_line.product_id):
# order = order.with_company(order.company_id)
# pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
# if not pickings:
# if order.order_line.product_id.categ_type == '胚料':
# res = order._prepare_picking_RES()
# else:
# res = order._prepare_picking()
# picking = StockPicking.with_user(SUPERUSER_ID).create(res)
# pickings = picking
# else:
# picking = pickings[0]
# moves = order.order_line._create_stock_moves(picking)
# moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm()
# seq = 0
# for move in sorted(moves, key=lambda move: move.date):
# seq += 5
# move.sequence = seq
# moves._action_assign()
# # Get following pickings (created by push rules) to confirm them as well.
# forward_pickings = self.env['stock.picking']._get_impacted_pickings(moves)
# (pickings | forward_pickings).action_confirm()
# picking.message_post_with_view('mail.message_origin_link',
# values={'self': picking, 'origin': order},
# subtype_id=self.env.ref('mail.mt_note').id)
# return True
#
#
# class ResPurchaseOrderLine(models.Model):
# _inherit = 'purchase.order.line'
#
# def _create_stock_moves(self, picking):
# values = []
# for line in self.filtered(lambda l: not l.display_type):
# for val in line._prepare_stock_moves(picking):
# val['production_id'] = 10
# values.append(val)
# line.move_dest_ids.created_purchase_line_id = False
#
# return self.env['stock.move'].create(values)
class ResPurchaseOrder(models.Model):
_inherit = 'purchase.order'
# def button_approve(self, force=False):
# result = super().button_approve(force=force)
# self._create_picking_RES()
# return result
# @api.depends('order_line.move_ids')
# def _compute_subcontracting_resupply_picking_count(self):
# for purchase in self:
# purchase.subcontracting_resupply_picking_count = len(purchase._get_subcontracting_resupplies_new())
#
# def _get_subcontracting_resupplies_new(self):
# moves_subcontracted = self.order_line.move_ids.filtered(lambda m: m.is_subcontract)
# # subcontracted_productions = moves_subcontracted.move_orig_ids.production_id
# return moves_subcontracted.picking_id
def _prepare_picking_RES(self):
if not self.group_id:
self.group_id = self.group_id.create({
'name': self.name,
'partner_id': self.partner_id.id
})
if not self.partner_id.property_stock_supplier.id:
raise UserError(_("You must set a Vendor Location for this partner %s", self.partner_id.name))
picking_type_id_res = self.env['stock.picking.type'].search(
[('sequence_code', '=', 'RES'), ('barcode', '=', 'WH-RESUPPLY')])
return {
'picking_type_id': picking_type_id_res.id if picking_type_id_res else self.picking_type_id.id,
'partner_id': self.partner_id.id,
'user_id': False,
'date': self.date_order,
'origin': self.name,
'location_dest_id': self._get_destination_location(),
'location_id': self.partner_id.property_stock_supplier.id,
'company_id': self.company_id.id,
}
def _create_picking(self):
StockPicking = self.env['stock.picking']
for order in self.filtered(lambda po: po.state in ('purchase', 'done')):
if any(product.type in ['product', 'consu'] for product in order.order_line.product_id):
order = order.with_company(order.company_id)
pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
if not pickings:
if order.order_line.product_id.categ_type == '胚料':
res = order._prepare_picking_RES()
else:
res = order._prepare_picking()
picking = StockPicking.with_user(SUPERUSER_ID).create(res)
pickings = picking
else:
picking = pickings[0]
moves = order.order_line._create_stock_moves(picking)
moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm()
seq = 0
for move in sorted(moves, key=lambda move: move.date):
seq += 5
move.sequence = seq
moves._action_assign()
# Get following pickings (created by push rules) to confirm them as well.
forward_pickings = self.env['stock.picking']._get_impacted_pickings(moves)
(pickings | forward_pickings).action_confirm()
picking.message_post_with_view('mail.message_origin_link',
values={'self': picking, 'origin': order},
subtype_id=self.env.ref('mail.mt_note').id)
return True
class ResPurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
def _create_stock_moves(self, picking):
values = []
for line in self.filtered(lambda l: not l.display_type):
for val in line._prepare_stock_moves(picking):
# val['production_id'] = 10
val['is_subcontract'] = True
values.append(val)
line.move_dest_ids.created_purchase_line_id = False
return self.env['stock.move'].create(values)