销售订单行
Sales order line
你好,我正在用 python 3.7 编写代码,我需要删除数量为 0 的销售产品订单。我被卡住了,我知道这很容易,但不是在这个时候对我来说。
我的最后更新代码:
init.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import api, fields
from . import models
from . import wizard
from . import report
from . import sale
from . import sale_order
from . import stock_no0
manifiest.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name' : 'Stock_0',
'version' : '0.1',
'summary': 'Invoices & Payments',
'sequence': 15,
'description': """
Stock No 0
====================
""",
'category': 'Invoicing Management',
'website': 'http://no_website.com',
'depends' : ['base_setup', 'product', 'sale', 'analytic', 'portal', 'digest'],
'data': [
'views/boton.xml',
],
'installable': True,
'application': True,
'auto_install': False,
}
stock_no0.py
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.onchange
def onchange_product_id_check_availability(self):
for ordr_ln in self.order_line:
if ordr_ln['qty_available'] < 0:
warning_mess = {'title': 'Opps! No hay stock',
'message': 'No hay suficiente Stock '}
@api.multi
def action_delete(self):
for order in self:
order.order_line.filtered(lambda l: not l.product_uom_qty).unlink()
XML
中的视图
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="view_order_form">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page/field[@name='order_line']" position="before">
<button name="action_delete" type="object" string="Clean" groups="sales_team.group_sale_manager"/>
</xpath>
</field>
</record>
</odoo>
错误是 AttributeError: type object 'sale.order' has no attribute 'action_delete'.
这些代码必须是 Odoo 12
谢谢。
你得到了 NameError: name 'models' is not defined
因为你没有导入 models
.
您可以使用 filtered 获取数量等于 0
的行,然后对结果(记录集)调用 unlink
方法。
from odoo import models, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def action_delete(self):
for order in self:
order.order_line.filtered(lambda l: not l.product_uom_qty).unlink()
在这种情况下,按钮类型应为 object
,其名称应为方法名称。
<button name="action_delete" type="object" string="Clean" groups="sales_team.group_sale_manager"/>
你好,我正在用 python 3.7 编写代码,我需要删除数量为 0 的销售产品订单。我被卡住了,我知道这很容易,但不是在这个时候对我来说。 我的最后更新代码:
init.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import api, fields
from . import models
from . import wizard
from . import report
from . import sale
from . import sale_order
from . import stock_no0
manifiest.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name' : 'Stock_0',
'version' : '0.1',
'summary': 'Invoices & Payments',
'sequence': 15,
'description': """
Stock No 0
====================
""",
'category': 'Invoicing Management',
'website': 'http://no_website.com',
'depends' : ['base_setup', 'product', 'sale', 'analytic', 'portal', 'digest'],
'data': [
'views/boton.xml',
],
'installable': True,
'application': True,
'auto_install': False,
}
stock_no0.py
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.onchange
def onchange_product_id_check_availability(self):
for ordr_ln in self.order_line:
if ordr_ln['qty_available'] < 0:
warning_mess = {'title': 'Opps! No hay stock',
'message': 'No hay suficiente Stock '}
@api.multi
def action_delete(self):
for order in self:
order.order_line.filtered(lambda l: not l.product_uom_qty).unlink()
XML
中的视图<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="view_order_form">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page/field[@name='order_line']" position="before">
<button name="action_delete" type="object" string="Clean" groups="sales_team.group_sale_manager"/>
</xpath>
</field>
</record>
</odoo>
错误是 AttributeError: type object 'sale.order' has no attribute 'action_delete'.
这些代码必须是 Odoo 12
谢谢。
你得到了 NameError: name 'models' is not defined
因为你没有导入 models
.
您可以使用 filtered 获取数量等于 0
的行,然后对结果(记录集)调用 unlink
方法。
from odoo import models, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def action_delete(self):
for order in self:
order.order_line.filtered(lambda l: not l.product_uom_qty).unlink()
在这种情况下,按钮类型应为 object
,其名称应为方法名称。
<button name="action_delete" type="object" string="Clean" groups="sales_team.group_sale_manager"/>