文件名称:
ODOO11报价单确认订单创建入库单(_run_move)
开发工具:
文件大小: 374kb
下载次数: 0
上传时间: 2019-01-12
详细说明:ODOO11报价单确认订单创建入库单(_run_move)
通过代码的分析和修改实践,了解odoo11 _run_move的运作模型: procurement. group
代码:
def run(self, product_ id, product qty, product_ uom, location_id, name, origin, values)
values. setdefault( comp
f.envllres.companyi.campanydefaultget('procurementgroup))
va⊥ues. setdetau⊥t
alues. setdefault(
lanned, fields. Datetime. now())
vd⊥ua
i+ not ru⊥Le
raise UserError(( No procurement rule found. Please verify the configuration of your routes))
getattr(rule, ' run %s' rule action)(product id, product_gty, product- uom, location_id, nane, origin, values)
return True
作用:在这里可以看到 getattr○方法,亡会根据产品所设置的路线,运行
run move和 run buy等方法。运行 run move等方法的时候,会传入一些值,
包括我们前面的 prepare procurement values()方法提取到的
sale. order.line的值并保存在 values中返回。这是一个批处理方法。
(5)由runO方法触发
run move
方法。
模块: stock
文件: procurement.py
模型: procurement.rule
代码:
det _run_move (selt, product_id, product_aty, product_uom, location_id, name, crigin, values)
msg =(No source location defined on procurement rule: %s!')%(self-name,
raisc UscrError(msg)
f self group propagation option =='propagate'
d' False) and values. 'grcup id].id
p propagation optIon
group id
1. gr'oup iu. iu
get stock move values( prcd
product_qty, product _uom, location_id, name, origin, values, group id)
#1
launch following
ement_group
hould activate it
mcvc=
作用: run move方法中,主要作用就是用于触发创建 stock.move(库存移动单)
和 stock. picking(出/入库单)。可以看到,我们上面传下来的 values被传到
get stock move values(方法中。
(6)由 run move(方法触发 get stock move values方法
模块: stock
文件: procurement.py
模型: procurement.rul
代码
produc
oduclyLy, produtL-uom, location_ id, udre, origin, values, group_iu)
vaLues that will be used to create a stock move from a proct
his function assumes that the given procurement has a rule (action ss 'nove set on ii ement.
Returns a dictionary
iparam procurement. hawse record
type di
date expected-(datetime. strptime(values[' date planned'1, DEFAULT SERVER DATETIME FORMAT)-relativedelta( days
I ready got some move de
orEe
y⊥e+t- prcduct gry
nanc': namcl:200」,
company id id or self location src id company idid or self location id company idid on
did or (values get('group_id', False)and values' group_id]partner
location src idid,
est ius] ur D
self, proture meLhod
self. picking type idid,
ute.id) for route in values get( route i
self propagate warehouse idid or self warehouse
'pricnity': values get('priority', 1")
作用:可以看到该方法返回的是一个字典,从(5)中可以看出,这里返回的字
典是用于创建 stock.move。要注意的是,每一个产品行都会创建一个
stock.move。
继承修改:前面我们在 values中加入了我们要传递的信息,在这里被这个函数
所接收,要注意的是,这个函数返回一个新构建的字典,字典的部分值从
values中取出,所以我们要继承并修改这个函数,为这个新构建的字典加入我
们 values中的值。
class ProcurementRule(models Model)
anner
procurement. rule'
api model
def get stock mcve values(self, product id, product qty product uom, location id, name
将 values中的 inquiry code和 inquiry code取出,构dato的链值
返国的值用于self.enu' stock,move'l. create(data)
Returns a dictionary nf values that will he used to create a stork move from a procurement
on assumes that the given procurement has a rule (action
move
ram procurement: browse record
data= super(Procurement le, celf) _get stock move values(product_id, product_nty, product_uom
locatio
name, origin, values, group id)
prcduct packaging: values[ prcduct packaging].id
要注意的是,由于我们返回的data是用于创建 stock.move,所以我们要在
stock.move中添加我们新的字段,让它顺利完成创建,免得报错
lass StockMove( models Model):
nherit =stock move
nquiry code= fields. Char(string='INQUTR'Y No')
packages- fields. Integer(string='Packages' compute=' compute packages ')
(7)由 run move(方法触发 assign picking(方法
模块: stock
文件: stock move.py
模型: stock.move
代码:
dek"" Try to nesign the moves to an existing picking thar has not hepn
assign_picking(self):
reserved yet and has the same procurement group, Locat ions and picking
type (moves should already have the identicaL). Otherwise, create a new
for move in
re comput
Picking search([
move group idid)
ocation
move location idid)
locaTion desL iu. id)
id)i
False
drafL, 'confirmed,'wdiLing','pdrLially_available, ' '])] limit=1)
f not picki
g
icking values())
move.write([ picking id: pickingid)y
H If this method is called in hatch hy a write on a cne2many and
H at sone point had to create a picking, some next iterations cculd
it tny to find back the created picking. As w look far it by scorching
H on some computed fields, we haye to force a recompute, else the
H record won 't be found
turn True
作用:在这个方法中,会创建一个 stock. picking模型的对象,并根据
stock.move中的信息来搜索出所对应的 stock. picking(出/入厍单),如果找不
到对应的 stock. picking,就会创建一个 stock. picking。最终,该
sock.moⅤe会被加入到对应的 slock. picking中。(可见:
move. write({‘ picking id’: picking.id})
(8)由_ assign picking(方法触发 get new picking values方法
模块: stock
文件; stock move.py
模型: stock.move
代码
def Lge=_new_picking_values(self)
Prepares a new picking for this move as it could not be assigned to
another picking. This method is designed to be inherited.
origin': self. origin
company id': self company id id
move type: self group id and self group id move type or direct
partner id: self partner id id
picking type id: self. picking type id id,
location_id: selflocation_idid
location dest id: self location dest idid,
作用:这是前面(7)中所提到的,当不存在 stock.move刈应的
stock. picking的时候,就会创建一个新的 stock. picking,该函数返回的值被
用于创建 stock. picking
(9)到这里,我们已经完成由报价单的确认订单按钮创建所对应的入库单全
流程。(sale. order→ stock. picking)。下一篇我们会讲确认订单生成询价
单
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.