我们在一家工业工厂工作,采购负责人必须将采购订单产品制造材料的任何采购通知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₺.
其中第一个表示当前材料价格,第二个表示每个销售订单的总金额。在
我们怎么处理?在
首先,我们将从通知过程开始。我们可以在这里使用一个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。在
继续代码,我们将获得向其发送消息的通道:
此外,我们还需要首席执行官经理合作伙伴:
^{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。在
我们有下一个代码:
从
price_subtotal
字段获取生产线的产品成本。在但我们想得到的总成本,因此:我们首先得到与当前行的PG相关的所有采购订单行,然后,我们迭代这些行,求出PO也得到确认的行:
第二个优势,正如我们在上面的代码中看到的那样:由于每个PG只有一个SO来源,我们不需要搜索
procurement_group_id.sale_id.id
字段,因为PGID只与一个SO关联,而没有其他的。在我们有了所需的所有信息,然后,我们将为PO中的每一行发送一条新消息:
我们必须添加货币符号,作为一个字段存在于行中,它是
line.currency_id.symbol
。在最后,我们的完整代码是:
每次确认采购订单:
相关问题 更多 >
编程相关推荐