Openerp 采购产品如何不创建新的采购订单
创建自动采购订单时,不要像Openerp 采购产品如何不创建新的采购订单,openerp,odoo-8,odoo-9,odoo-10,odoo-view,Openerp,Odoo 8,Odoo 9,Odoo 10,Odoo View,创建自动采购订单时,不要像Odoo那样对现有订单上的项目进行分组,但必须将其拆分 自动创建采购订单(订单采购)时,不要将项目现有采购订单草案上的项目分组,而是系统地创建新采购订单 我想覆盖创建新采购订单的功能,以提供现有采购订单中未创建的物品 def _make_po_get_domain(self, partner): gpo = self.rule_id.group_propagation_option group = (gpo == 'fixed' and self
Odoo
那样对现有订单上的项目进行分组,但必须将其拆分
自动创建采购订单(订单采购)时,不要将项目现有采购订单草案上的项目分组,而是系统地创建新采购订单
我想覆盖创建新采购订单的功能,以提供现有采购订单中未创建的物品
def _make_po_get_domain(self, partner):
gpo = self.rule_id.group_propagation_option
group = (gpo == 'fixed' and self.rule_id.group_id) or \
(gpo == 'propagate' and self.group_id) or False
domain = (
('partner_id', '=', partner.id),
('state', '=', 'draft'),
('picking_type_id', '=', self.rule_id.picking_type_id.id),
('company_id', '=', self.company_id.id),
('dest_address_id', '=', self.partner_dest_id.id))
if group:
domain += (('group_id', '=', group.id),)
return domain
@api.multi
def make_po(self):
cache = {}
res = []
for procurement in self:
suppliers = procurement.product_id.seller_ids\
.filtered(lambda r: (not r.company_id or r.company_id == procurement.company_id) and (not r.product_id or r.product_id == procurement.product_id))
if not suppliers:
procurement.message_post(body=_('No vendor associated to product %s. Please set one to fix this procurement.') % (procurement.product_id.name))
continue
supplier = procurement._make_po_select_supplier(suppliers)
partner = supplier.name
domain = procurement._make_po_get_domain(partner)
if domain in cache:
po = cache[domain]
else:
po = self.env['purchase.order'].search([dom for dom in domain])
po = po[0] if po else False
cache[domain] = po
if not po:
vals = procurement._prepare_purchase_order(partner)
po = self.env['purchase.order'].create(vals)
name = (procurement.group_id and (procurement.group_id.name + ":") or "") + (procurement.name != "/" and procurement.name or procurement.move_dest_id.raw_material_production_id and procurement.move_dest_id.raw_material_production_id.name or "")
message = _("This purchase order has been created from: <a href=# data-oe-model=procurement.order data-oe-id=%d>%s</a>") % (procurement.id, name)
po.message_post(body=message)
cache[domain] = po
elif not po.origin or procurement.origin not in po.origin.split(', '):
# Keep track of all procurements
if po.origin:
if procurement.origin:
po.write({'origin': po.origin + ', ' + procurement.origin})
else:
po.write({'origin': po.origin})
else:
po.write({'origin': procurement.origin})
name = (self.group_id and (self.group_id.name + ":") or "") + (self.name != "/" and self.name or self.move_dest_id.raw_material_production_id and self.move_dest_id.raw_material_production_id.name or "")
message = _("This purchase order has been modified from: <a href=# data-oe-model=procurement.order data-oe-id=%d>%s</a>") % (procurement.id, name)
po.message_post(body=message)
if po:
res += [procurement.id]
# Create Line
po_line = False
for line in po.order_line:
if line.product_id == procurement.product_id and line.product_uom == procurement.product_id.uom_po_id:
procurement_uom_po_qty = procurement.product_uom._compute_quantity(procurement.product_qty, procurement.product_id.uom_po_id)
seller = procurement.product_id._select_seller(
partner_id=partner,
quantity=line.product_qty + procurement_uom_po_qty,
date=po.date_order and po.date_order[:10],
uom_id=procurement.product_id.uom_po_id)
price_unit = self.env['account.tax']._fix_tax_included_price_company(seller.price, line.product_id.supplier_taxes_id, line.taxes_id, self.company_id) if seller else 0.0
if price_unit and seller and po.currency_id and seller.currency_id != po.currency_id:
price_unit = seller.currency_id.compute(price_unit, po.currency_id)
po_line = line.write({
'product_qty': line.product_qty + procurement_uom_po_qty,
'price_unit': price_unit,
'procurement_ids': [(4, procurement.id)]
})
break
if not po_line:
vals = procurement._prepare_purchase_order_line(po, supplier)
self.env['purchase.order.line'].create(vals)
return res
def\u make\u po\u get\u域(自身、合作伙伴):
gpo=自治\u id.group\u传播\u选项
组=(gpo=='fixed'和self.rule\u id.group\u id)或\
(gpo=='propagate'和self.group_id)或False
域=(
('partner_id','=',partner.id),
('state','=','draft'),
('picking_type_id','=',self.rule_id.picking_type_id.id),
('company_id','=',self.company_id.id),
('dest_address_id','=',self.partner_dest_id.id))
如果组:
域+=(('group_id','=',group.id),)
返回域
@api.multi
def make_po(自身):
缓存={}
res=[]
对于自行采购:
供应商=采购部、产品部、卖方部\
.filtered(lambda r:(不是r.company\u id或r.company\u id==采购.公司id)和(不是r.product\u id或r.product\u id==采购.产品id))
如果不是供应商:
procurement.message_post(body=u('没有与产品%s关联的供应商。请设置一个以修复此采购')%(procurement.product_id.name))
持续
供应商=采购。\制定\采购\选择\供应商(供应商)
合作伙伴=供应商名称
域=采购。_make_po_get_domain(合作伙伴)
如果域在缓存中:
po=缓存[域]
其他:
po=self.env['purchase.order'].search([dom代表域中的dom])
如果采购订单为假,则采购订单=采购订单[0]
缓存[域]=po
如果不是采购订单:
VAL=采购。\准备\采购订单(合作伙伴)
po=self.env['purchase.order'].create(VAL)
name=(procurement.group\u id和(procurement.group\u id.name+“:”)或“”)+(procurement.name!=“/”和procurement.name或procurement.move\u dest\u id.raw\u material\u production\u id和procurement.move\u dest\u id.raw\u material\u production\u id.name或“”)
消息=((“此采购订单是从以下位置创建的):%(procurement.id,name)
采购订单信息发布(正文=信息)
缓存[域]=po
elif非采购订单原产地或采购订单原产地不在采购订单原产地分割(','):
#跟踪所有采购
如果采购订单来源:
如果采购来源:
po.write({'origin':po.origin+,'+procurement.origin})
其他:
po.write({'origin':po.origin})
其他:
po.write({'origin':procurement.origin})
名称=(self.group\u id和(self.group\u id.name+“:”)或“”)+(self.name!=“/”和self.name或self.move\u dest\u id.raw\u material\u production\u id和self.move\u dest\u id.raw\u material\u production\u id.name或“”)
消息=((“此采购订单已从:”)修改%(procurement.id,name)
采购订单信息发布(正文=信息)
如果采购订单:
res+=[procurement.id]
#创建线
po_线=假
对于采购订单行中的行:
如果line.product\u id==procurement.product\u id和line.product\u uom==procurement.product\u id.uom\u po\u id:
采购数量=采购。产品数量。计算数量(采购。产品数量,采购。产品id。计量单位采购id)
卖方=采购。产品\u id.\u选择\u卖方(
partner_id=partner,
数量=行产品数量+采购数量,
日期=订单日期和订单日期[:10],
计量单位标识=采购.产品标识.计量单位采购订单标识)
价格单位=self.env['account.tax']。\u固定\u tax\u包括公司价格(卖方价格、行产品、供应商、税种、行税种、self.company\u id),如果卖方为0.0
如果价格单位和卖方以及采购订单货币id和卖方货币id!=采购订单货币号:
价格单位=卖方.currency\u id.compute(价格单位,采购订单.currency\u id)
po_line=line.write({
“产品数量”:行。产品数量+采购数量,
“价格单位”:价格单位,
“采购id”:[(4,procurement.id)]
})
打破
如果不是po_线:
VAL=采购。\准备\采购订单\行(采购订单、供应商)
self.env['purchase.order.line'].create(VAL)
返回res