修复报废

This commit is contained in:
jinling.yang
2024-08-16 17:28:21 +08:00
parent e2d7576a5e
commit 3c8dac799d
5 changed files with 85 additions and 32 deletions

View File

@@ -36,7 +36,7 @@ class Http(models.AbstractModel):
post_time = int(datas['HTTP_TIMESTAMP']) post_time = int(datas['HTTP_TIMESTAMP'])
datetime_post = datetime.fromtimestamp(post_time) datetime_post = datetime.fromtimestamp(post_time)
datetime_now = datetime.now().replace(microsecond=0) datetime_now = datetime.now().replace(microsecond=0)
datetime_del = datetime_now + timedelta(seconds=5) datetime_del = datetime_now + timedelta(seconds=30)
if datetime_post > datetime_del: if datetime_post > datetime_del:
raise AuthenticationError('请求已过期') raise AuthenticationError('请求已过期')
check_str = '%s%s%s' % (datas['HTTP_TOKEN'], post_time, factory_secret.sf_secret_key) check_str = '%s%s%s' % (datas['HTTP_TOKEN'], post_time, factory_secret.sf_secret_key)

View File

@@ -934,17 +934,50 @@ class MrpProduction(models.Model):
logging.info('get_new_program error:%s' % e) logging.info('get_new_program error:%s' % e)
raise UserError("从云平台获取最新程序失败,请联系管理员") raise UserError("从云平台获取最新程序失败,请联系管理员")
def recreateManufacturing(self, item): def recreateManufacturing(self, item, procurement, rule):
""" """
重新生成制造订单 重新生成制造订单
""" """
if self.is_scrap is True: if self.is_scrap is True:
procurement_requests = []
sale_order = self.env['sale.order'].sudo().search([('name', '=', self.origin)]) sale_order = self.env['sale.order'].sudo().search([('name', '=', self.origin)])
values = self.env['mrp.production'].create_production1_values(self) values = self.env['mrp.production'].create_production1_values(self)
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company( productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
self.company_id).create( self.company_id).create(
values) values)
# moves_values = [{''}] # 查询出库移动记录
out_picking = self.env['stock.picking'].search(
[('logistics_way', '!=', False), ('origin', '=', sale_order.name), ('name', 'ilike', 'WH/OUT/')])
for move in out_picking.move_ids:
values = move._prepare_procurement_values()
origin = move._prepare_procurement_origin()
procurement_requests.append(self.env['procurement.group'].Procurement(
move.product_id, move.product_uom_qty, move.product_uom,
move.location_id, move.rule_id and move.rule_id.name or "/",
origin, move.company_id, values))
self.env['procurement.group'].run(procurement_requests,
raise_user_error=not self.env.context.get('from_orderpoint'))
for procurement, rule in procurements:
if not rule.location_src_id:
msg = _('No source location defined on stock rule: %s!') % (rule.name,)
raise ProcurementException([(procurement, msg)])
if rule.procure_method == 'mts_else_mto':
mtso_products_by_locations[rule.location_src_id].append(procurement.product_id.id)
# out_picking.move_ids._action_confirm()
# self.env['stock.move'].search([('')])
# for
move_values = rule._get_stock_move_values(*procurement)
move_values['procure_method'] = 'make_to_order'
moves_values_by_company[procurement.company_id.id].append(move_values)
# moves_values = [{'name': ,''}]
for company_id, moves_values in moves_values_by_company.items():
logging.info(moves_values)
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
moves_values)
logging.info(moves)
# Since action_confirm launch following procurement_group we should activate it.
moves._action_confirm()
# moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(moves_values) # moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(moves_values)
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) # self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) self.env['stock.move'].sudo().create(productions._get_moves_finished_values())

View File

@@ -179,6 +179,7 @@ class StockRule(models.Model):
# launched by a sale for example) # launched by a sale for example)
logging.info(moves_values) logging.info(moves_values)
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(moves_values) moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(moves_values)
logging.info(moves)
# Since action_confirm launch following procurement_group we should activate it. # Since action_confirm launch following procurement_group we should activate it.
moves._action_confirm() moves._action_confirm()

View File

@@ -82,6 +82,7 @@
<xpath expr="//sheet//group//group//div[3]" position="after"> <xpath expr="//sheet//group//group//div[3]" position="after">
<field name="manual_quotation" readonly="1"/> <field name="manual_quotation" readonly="1"/>
<field name="programming_no" readonly="1"/> <field name="programming_no" readonly="1"/>
<field name="confirm_cancel" readonly="1"/>
<field name="programming_state" readonly="1" <field name="programming_state" readonly="1"
decoration-success="programming_state == '已编程'" decoration-success="programming_state == '已编程'"
decoration-warning="programming_state =='编程中'" decoration-warning="programming_state =='编程中'"
@@ -103,11 +104,11 @@
<field name="tool_state_remark" string="备注" attrs="{'invisible': [('tool_state', '!=', '1')]}"/> <field name="tool_state_remark" string="备注" attrs="{'invisible': [('tool_state', '!=', '1')]}"/>
<field name="tool_state_remark2" invisible="1"/> <field name="tool_state_remark2" invisible="1"/>
</xpath> </xpath>
<xpath expr="//header//button[@name='action_cancel']" position="replace"> <!-- <xpath expr="//header//button[@name='action_cancel']" position="replace">-->
<button name="action_cancel" type="object" string="取消" data-hotkey="z" <!-- <button name="action_cancel" type="object" string="取消" data-hotkey="z"-->
attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', True)]}" <!-- attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', True)]}"-->
groups="sf_base.group_sf_mrp_user"/> <!-- groups="sf_base.group_sf_mrp_user"/>-->
</xpath> <!-- </xpath>-->
<xpath expr="(//header//button[@name='button_mark_done'])[1]" position="replace"> <xpath expr="(//header//button[@name='button_mark_done'])[1]" position="replace">
<button name="button_mark_done" <button name="button_mark_done"
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft', 'cancel', 'done', 'to_close')), ('qty_producing', '=', 0), ('move_raw_ids', '!=', [])]}" attrs="{'invisible': ['|', '|', ('state', 'in', ('draft', 'cancel', 'done', 'to_close')), ('qty_producing', '=', 0), ('move_raw_ids', '!=', [])]}"
@@ -215,12 +216,12 @@
type="object" groups="sf_base.group_sf_mrp_user"/> type="object" groups="sf_base.group_sf_mrp_user"/>
</xpath> </xpath>
<xpath expr="//header//button[@name='action_cancel']" position="replace"> <!-- <xpath expr="//header//button[@name='action_cancel']" position="replace">-->
<button name="action_cancel" type="object" string="Cancel" data-hotkey="z" <!-- <button name="action_cancel" type="object" string="Cancel" data-hotkey="z"-->
attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', False)]}" <!-- attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', False)]}"-->
confirm="Some product moves have already been confirmed, this manufacturing order can't be completely cancelled. Are you still sure you want to process ?" <!-- confirm="Some product moves have already been confirmed, this manufacturing order can't be completely cancelled. Are you still sure you want to process ?"-->
groups="sf_base.group_sf_mrp_user"/> <!-- groups="sf_base.group_sf_mrp_user"/>-->
</xpath> <!-- </xpath>-->
<xpath expr="//header//button[@name='button_unbuild']" position="replace"> <xpath expr="//header//button[@name='button_unbuild']" position="replace">
<button name="button_unbuild" type="object" string="拆单" <button name="button_unbuild" type="object" string="拆单"
@@ -265,12 +266,12 @@
type="object" groups="sf_base.group_sf_mrp_user"/> type="object" groups="sf_base.group_sf_mrp_user"/>
</xpath> </xpath>
<xpath expr="//header//button[@name='action_cancel']" position="replace"> <!-- <xpath expr="//header//button[@name='action_cancel']" position="replace">-->
<button name="action_cancel" type="object" string="取消" data-hotkey="z" <!-- <button name="action_cancel" type="object" string="取消" data-hotkey="z"-->
attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', False)]}" <!-- attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', False)]}"-->
confirm="Some product moves have already been confirmed, this manufacturing order can't be completely cancelled. Are you still sure you want to process ?" <!-- confirm="Some product moves have already been confirmed, this manufacturing order can't be completely cancelled. Are you still sure you want to process ?"-->
groups="sf_base.group_sf_mrp_user"/> <!-- groups="sf_base.group_sf_mrp_user"/>-->
</xpath> <!-- </xpath>-->
<xpath expr="//header//button[@name='button_unbuild']" position="replace"> <xpath expr="//header//button[@name='button_unbuild']" position="replace">
<button name="button_unbuild" type="object" string="拆单" <button name="button_unbuild" type="object" string="拆单"
attrs="{'invisible': [('state', '!=', 'done')]}" data-hotkey="shift+v" attrs="{'invisible': [('state', '!=', 'done')]}" data-hotkey="shift+v"
@@ -421,9 +422,9 @@
<xpath expr="//header//button[@name='do_unreserve']" position="replace"> <xpath expr="//header//button[@name='do_unreserve']" position="replace">
<button name="do_unreserve" type="object" string="取消保留" groups="sf_base.group_sf_mrp_user"/> <button name="do_unreserve" type="object" string="取消保留" groups="sf_base.group_sf_mrp_user"/>
</xpath> </xpath>
<xpath expr="//header//button[@name='action_cancel']" position="replace"> <!-- <xpath expr="//header//button[@name='action_cancel']" position="replace">-->
<button name="action_cancel" type="object" string="取消" groups="sf_base.group_sf_mrp_user"/> <!-- <button name="action_cancel" type="object" string="取消" groups="sf_base.group_sf_mrp_user"/>-->
</xpath> <!-- </xpath>-->
<xpath expr="//field[@name='state']" position="after"> <xpath expr="//field[@name='state']" position="after">
<field name="tool_state" invisible="1"/> <field name="tool_state" invisible="1"/>
</xpath> </xpath>

View File

@@ -71,6 +71,8 @@ class ProductionWizard(models.TransientModel):
'%Y-%m-%d %H:%M:%S') '%Y-%m-%d %H:%M:%S')
} }
ret['programming_list'].append(vals) ret['programming_list'].append(vals)
actions_to_run = defaultdict(list)
list2 = [] list2 = []
Procurement = namedtuple('Procurement', ['product_id', 'product_qty', Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
'product_uom', 'location_id', 'name', 'origin', 'product_uom', 'location_id', 'name', 'origin',
@@ -78,30 +80,46 @@ class ProductionWizard(models.TransientModel):
'values']) 'values'])
s = Procurement(product_id=self.production_id.product_id, product_qty=1.0, s = Procurement(product_id=self.production_id.product_id, product_qty=1.0,
product_uom=self.production_id.product_uom_id, product_uom=self.production_id.product_uom_id,
location_id=self.production_id.product_id.route_ids[1], location_id=self.env['stock.location'].search([('usage', '=', 'customer')]),
name=self.production_id.product_id.display_name, name=self.production_id.product_id.display_name,
origin=self.production_id.origin, origin=self.production_id.origin,
company_id=self.production_id.company_id, company_id=self.production_id.company_id,
values={ values={
'group_id': self.production_id.procurement_group_id.id, 'group_id': self.production_id.procurement_group_id,
'sale_line_id': False, 'sale_line_id': False,
'date_planned': fields.Date.today(), 'date_planned': fields.Date.today(),
'date_deadline': fields.Date.today(), 'date_deadline': fields.Date.today(),
# 'route_ids': stock.route(), # 'route_ids': stock.route(),
'warehouse_id': self.production_id.warehouse_id.id, 'warehouse_id': self.production_id.warehouse_id,
# 'partner_id': self.production_id.partner_id, # 'partner_id': self.production_id.partner_id,
'product_description_variants': '', 'product_description_variants': '',
'company_id': self.production_id.company_id.id, 'company_id': self.production_id.company_id,
# 'product_packaging_id': product.packaging(), # 'product_packaging_id': product.packaging(),
'sequence': 10, 'sequence': 10,
'priority': '0' 'priority': '0'
}, },
) )
list2.append(tuple(s)) rule = self.env['procurement.group']._get_rule(s.product_id, s.location_id,s.values)
list2.append(self.production_id.product_id.route_ids[1]) list2.append(s)
actions_to_run = defaultdict(list2) # for procurement in list2:
self.env['stock.rule']._run_pull(actions_to_run) # rule = self.env['procurement.group']._get_rule(procurement.product_id, procurement.location_id,
# new_production = self.production_id.recreateManufacturing(ret) # procurement.values)
# action = 'pull'
# actions_to_run[action].append((procurement, rule))
# # list2.append(tuple(s))
# # list2.append(self.production_id.product_id.route_ids[1])
# for action, procurements in actions_to_run.items():
# bb = action
# aa = procurements
# if hasattr(self.env['stock.rule'], '_run_%s' % action):
# try:
# getattr(self.env['stock.rule'], '_run_%s' % action)(procurements)
# except ProcurementException as e:
# procurement_errors += e.procurement_exceptions
# else:
# _logger.error("The method _run_%s doesn't exist on the procurement rules" % action)
# self.env['stock.rule']._run_pull(actions_to_run)
new_production = self.production_id.recreateManufacturing(ret, s, rule)
if self.is_reprogramming is False: if self.is_reprogramming is False:
for panel in new_production.product_id.model_processing_panel.split(','): for panel in new_production.product_id.model_processing_panel.split(','):
scrap_cnc_workorder = max( scrap_cnc_workorder = max(