在Od中通过销售订单通知采购

2024-09-29 05:23:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我们在一家工业工厂工作,采购负责人必须将采购订单产品制造材料的任何采购通知CEO。在

例如,我们有一个销售订单SO00005,产品[856A3779G02] PULLER – PLATFORM, FAN BLADE,它有自己的BoM,还有{}和{}路线。在

系统将创建一个新的采购订单,负责编辑并处理路线,在确认时,我们必须向CEO发送如下消息:

SO00005 adlı [856A3779G02] PULLER – PLATFORM, FAN BLADE projesi için toplam maliyet 100.0₺'dir.

SO00005 adlı [856A3779G02] PULLER – PLATFORM, FAN BLADE şindiye kadarki toplam maliyet 1175.0₺.

其中第一个表示当前材料价格,第二个表示每个销售订单的总金额。在

我们怎么处理?在


Tags: 订单产品工厂路线platform负责人工业adl
1条回答
网友
1楼 · 发布于 2024-09-29 05:23:54

首先,我们将从通知过程开始。我们可以在这里使用一个automated action,以便使这个操作尽可能简单。在

自动操作

我们转到Settings > Technical > Automation > Automated Actions(别忘了安装base_automation模块),然后用下面的参数创建一个新操作:

模型purchase.order,我们希望在点击确认订单按钮时通知,将当前采购状态更改为采购触发条件:更新时,我们希望在确认采购订单时发送此通知,这意味着当采购订单将其状态更改为purchase更新前域:所以,之前的域将全部为当前草稿,以批准或通过电子邮件发送的采购订单,["|","|",["state","=","draft"],["state","=","sent"],["state","=","to approve"]]应用于:我们将在采购订单的状态更改为purchase[["state","=","purchase"]]时发送此邮件。 要做的操作:最后,我们将应用一个python代码来获取所需的信息并将其发送给老板。在

Python代码

我们决定使用python代码,因为它更容易在代码中迭代对象;我们的意思是,我们也可以发送电子邮件作为要做的操作,但在这种情况下,我们需要将purchase.order.line作为小时模型,这可能更困难。在

现在,最简单的方法就是向Odoo内部的一个通道发送消息,尽可能多地保留系统中的过程。因此,在创建此操作之前,我们必须在讨论模块中create a private or public channel。在

继续代码,我们将获得向其发送消息的通道:

channel = env['mail.channel'].search([('name', '=', 'purchases-notify')])
channel.ensure_one()

此外,我们还需要首席执行官经理合作伙伴:

^{pr2}$

现在,我们将迭代采购订单中的每一行来处理信息;我们必须在这里选择,默认情况下,Odoo中的tracking purchases and other expenses使用会计模块和流程,这意味着,我们必须向采购订单中的每一行添加分析账户,并且,如果采购订单有许多不同的产品,可能会非常烦人。我们将使用其他接近。在

生产订单和销售订单根据采购规则生成采购组采购组has a unique Sale Order origin,这对我们来说是一个双重优势:第一,通过这种关系我们可以得到产品的名称;这个PG也有SO的名字。在

默认情况下,Odoo不会按PG组拆分每个采购行,如果产品产品变体uom相同,则只会合并这些行,而且我们也无法知道哪个PG是it行的来源;要解决这个问题,我们必须从安装purchase_line_procurement_group模块OCA。在

我们有下一个代码:

for line in record.order_line:
  procurement_group = line.procurement_group_id
  product = env['sale.order'].search([('id', '=', procurement_group.sale_id.id)]).order_line[0].name
  sub_total = line.price_subtotal

price_subtotal字段获取生产线的产品成本。在

但我们想得到的总成本,因此:我们首先得到与当前行的PG相关的所有采购订单行,然后,我们迭代这些行,求出PO也得到确认的行:

purchase_order_lines_list = env['purchase.order.line'].search([('procurement_group_id','=',procurement_group.id)])
  total = 0
  for line in purchase_order_lines_list:
    if line.order_id.state == 'purchase':
      total += line.price_subtotal

第二个优势,正如我们在上面的代码中看到的那样:由于每个PG只有一个SO来源,我们不需要搜索procurement_group_id.sale_id.id字段,因为PGID只与一个SO关联,而没有其他的。在

我们有了所需的所有信息,然后,我们将为PO中的每一行发送一条新消息:

post_vars = {
    'subject': "Purchase {}".format(record.name),
    'body': '''<p>Mr. <strong>{0}</strong>,</p>
        <p><strong>{1}</strong> adlı <strong>{2}</strong> projesi için toplam maliyet <strong>{3}{4}</strong>'dir.</p>
        <p><strong>{1}</strong> adlı <strong>{2}</strong> şindiye kadarki toplam maliyet <strong>{5}{4}</strong>.</p>'''.format(boss.name, procurement_group.name, product, sub_total, line.currency_id.symbol, total)
  }
  channel.message_post(type="notification", subtype="mt_comment", **post_vars)

我们必须添加货币符号,作为一个字段存在于行中,它是line.currency_id.symbol。在

最后,我们的完整代码是:

channel = env['mail.channel'].search([('name', '=', 'purchases-notify')])
channel.ensure_one()


boss = env['res.partner'].search([('function', '=', 'CEO')])

for line in record.order_line:
  procurement_group = line.procurement_group_id
  product = env['sale.order'].search([('id', '=', procurement_group.sale_id.id)]).order_line[0].name
  sub_total = line.price_subtotal
  purchase_order_lines_list = env['purchase.order.line'].search([('procurement_group_id','=',procurement_group.id)])
  total = 0
  for line in purchase_order_lines_list:
    if line.order_id.state == 'purchase':
      total += line.price_subtotal
  post_vars = {
    'subject': "Purchase {}".format(record.name),
    'body': '''<p>Mr. <strong>{0}</strong>,</p>
        <p><strong>{1}</strong> adlı <strong>{2}</strong> projesi için toplam maliyet <strong>{3}{4}</strong>'dir.</p>
        <p><strong>{1}</strong> adlı <strong>{2}</strong> şindiye kadarki toplam maliyet <strong>{5}{4}</strong>.</p>'''.format(boss.name, procurement_group.name, product, sub_total, line.currency_id.symbol, total)
  }
  channel.message_post(type="notification", subtype="mt_comment", **post_vars)

每次确认采购订单enter image description here

相关问题 更多 >