models.py中有下面的一个模型-sell_return_order:
# 新建退货单据表sell.return.order,应包含以下字段(具体根据导出模板实际业务进行增减)
class sell_return_order(models.Model):
_name = 'sell.return.order'
_description = u'退货单据'
_inherits = {'sell.order': 'sell_order_id'} #
_order = 'id desc'
name = fields.Char(string=u'RMA单据ID')
sell_order_id = fields.Many2one('sell.order',string=u"销售单据",required=True) # 与销售单据关联关系(多对一)
reason_id = fields.Many2one('return.reason', string=u'退货原因') # 从退货原因字典表中获取
number = fields.Integer(string=u'退货数量', compute='_compute_number')
weight = fields.Float(string=u'实际重量', compute='_compute_weight')
compen_money = fields.Float(string=u'补偿金额') # 退款金额之外的金额
back_method = fields.Char(string=u'退款方式')
tracking_number = fields.Char(string=u'物流单号') # 物流单号
back_time = fields.Datetime(string=u'退回时间', default=fields.Datetime.now) # 默认当前时间
remark = fields.Char(string=u'备注')
# 按照退货商品价格计算出来的,目前可手动填写,但需做一个判断,若是退款金额大于商品价格,则退货失败
resend_number = fields.Char(string=u'重发订单')
send_date = fields.Datetime(string=u'发货日期',related = 'sell_order_id.send_time',store=True) # 发货日期
back_state = fields.Selection(selection=[('draft', u'草稿'),('return',u'退货中'),('done',u'已收货')] ,string=u'退回状态', default='draft')
back_money = fields.Char(string=u'退款金额') #
line_ids = fields.One2many('return.order.line', 'sell_return_order_id', string=u'退货单据行', help=u'退货单据的明细行,不能为空')
页面的中的tree视图代码sell_return_order.xml:
<!--生成退货单 tree视图-->
<record id='sell_return_order_tree' model='ir.ui.view'>
<field name='name'>退货单据列表</field>
<field name='model'>sell.return.order</field> <!--类名,即表名-->
<field name='arch' type='xml'>
<tree string='销售退货单' create="false" decoration-muted="back_state=='done'">
<field name="name" string="RMA单据ID"/>
<field name="sell_order_id" string="订单号"/>
<field name="resend_number" string="重发订单"/>
<field name="store_id" string="账号"/>
<field name="partner_id" string="buyerID"/>
<field name="send_time"/>
<field name="reason_id" string="退货原因"/>
<field name="country" string="国家"/>
<field name="back_method" string="退回方式"/>
<field name="tracking_number" string="追踪单号"/>
<field name="back_state" string="退回状态"/>
<field name="back_time" string="退回时间"/>
<field name="shipping_id" string='快递方式'/>
<field name="currency_id" string='币种'/>
<field name="amount" string='订单总金额'/>
<field name="back_money" string='退款金额'/>
<field name="back_method" string='退款方式'/>
<field name="compen_money" string='补偿金额'/>
<field name="remark" string='备注'/>
<field name="state" invisible="1"/>
<button name="action_link_form" string="详细" type="object" />
<button name="action_retail_order_message_info" string="操作日志" type="object"
class='oe_highlight'/>
</tree>
</field>
</record>
页面效果如下:
image.png
现在要在tree视图的页面中,完善搜索功能,实现可以模糊查询,按条件筛选,按指定条件分组展示的效果,代码如下:
<!--搜索,模糊查询(按属性模糊查询),筛选,分组-->
<record id="sell_return_order_search" model="ir.ui.view">
<field name="name">退货单据</field>
<field name="model">sell.return.order</field>
<field name="arch" type="xml">
<search string="退货单据搜索">
<field name="name"/>
<field name="sell_order_id"/>
<field name="tracking_number"/>
<separator/>
<filter string="草稿" domain="[('back_state','=','draft')]"/>
<filter string="退货中" domain="[('back_state','=','return')]"/>
<filter string="已收货" domain="[('back_state','=','done')]"/>
<separator/>
<group expand="0" string="分组">
<filter string="退货原因" domain="[]" context="{'group_by':'reason_id'}" />
<filter string="退货状态" domain="[]" context="{'group_by':'back_state'}" />
</group>
</search>
</field>
</record>
实现的页面效果如下,代码中的<separator>显示为一条分割线:
模糊查询:
image.png
筛选:
image.png
按条件分组:
image.png
网友评论