采购申请字段调整
This commit is contained in:
@@ -2,4 +2,5 @@
|
|||||||
from . import product_template
|
from . import product_template
|
||||||
from . import purchase_request
|
from . import purchase_request
|
||||||
from . import sale_order
|
from . import sale_order
|
||||||
|
from . import purchase_order
|
||||||
from . import stock_rule
|
from . import stock_rule
|
||||||
|
|||||||
16
jikimo_purchase_request/models/purchase_order.py
Normal file
16
jikimo_purchase_request/models/purchase_order.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from odoo import api, fields, models, _
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseOrder(models.Model):
|
||||||
|
_inherit = 'purchase.order'
|
||||||
|
|
||||||
|
state = fields.Selection([
|
||||||
|
('draft', '询价'),
|
||||||
|
('sent', '发送询价'),
|
||||||
|
('to approve', '待批准'),
|
||||||
|
("approved", "已批准"),
|
||||||
|
('purchase', '采购订单'),
|
||||||
|
('done', '完成'),
|
||||||
|
('cancel', '取消'),
|
||||||
|
('rejected', '已驳回')
|
||||||
|
], string='Status', readonly=True, index=True, copy=False, default='draft', tracking=True)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
|
|
||||||
|
|
||||||
@@ -25,6 +26,12 @@ class PurchaseRequestLine(models.Model):
|
|||||||
_description = '采购申请明细'
|
_description = '采购申请明细'
|
||||||
|
|
||||||
origin = fields.Char(string="Source Document")
|
origin = fields.Char(string="Source Document")
|
||||||
|
|
||||||
|
part_number = fields.Char('零件图号', store=True, compute='_compute_part_number')
|
||||||
|
part_name = fields.Char('零件名称', store=True, compute='_compute_part_name')
|
||||||
|
related_product = fields.Many2one('product.product', string='关联产品',
|
||||||
|
help='经此产品工艺加工成的成品')
|
||||||
|
|
||||||
supply_method = fields.Selection([
|
supply_method = fields.Selection([
|
||||||
('automation', "自动化产线加工"),
|
('automation', "自动化产线加工"),
|
||||||
('manual', "人工线下加工"),
|
('manual', "人工线下加工"),
|
||||||
@@ -56,3 +63,30 @@ class PurchaseRequestLine(models.Model):
|
|||||||
prl.supply_method = order_line[0].supply_method
|
prl.supply_method = order_line[0].supply_method
|
||||||
else:
|
else:
|
||||||
prl.supply_method = None
|
prl.supply_method = None
|
||||||
|
|
||||||
|
@api.depends('product_id')
|
||||||
|
def _compute_part_number(self):
|
||||||
|
for record in self:
|
||||||
|
if record.part_number and record.part_name:
|
||||||
|
continue
|
||||||
|
if record.product_id.categ_id.name == '坯料':
|
||||||
|
product_name = ''
|
||||||
|
match = re.search(r'(S\d{5}-\d)', record.product_id.name)
|
||||||
|
# 如果匹配成功,提取结果
|
||||||
|
if match:
|
||||||
|
product_name = match.group(0)
|
||||||
|
sale_order_name = ''
|
||||||
|
match_sale = re.search(r'S(\d+)', record.product_id.name)
|
||||||
|
if match_sale:
|
||||||
|
sale_order_name = match_sale.group(0)
|
||||||
|
sale_order = self.env['sale.order'].sudo().search(
|
||||||
|
[('name', '=', sale_order_name)])
|
||||||
|
if sale_order:
|
||||||
|
filtered_order_line = sale_order.order_line.filtered(
|
||||||
|
lambda order_line: re.search(f'{product_name}$', order_line.product_id.name)
|
||||||
|
)
|
||||||
|
record.part_number = filtered_order_line.product_id.part_number
|
||||||
|
record.part_name = filtered_order_line.product_id.part_name
|
||||||
|
else:
|
||||||
|
record.part_number = record.product_id.part_number
|
||||||
|
record.part_name = record.product_id.part_name
|
||||||
|
|||||||
@@ -10,6 +10,55 @@
|
|||||||
<xpath expr="//field[@name='line_ids']//field[@name='purchased_qty']" position="after">
|
<xpath expr="//field[@name='line_ids']//field[@name='purchased_qty']" position="after">
|
||||||
<field name="supply_method"/>
|
<field name="supply_method"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='line_ids']//field[@name='name']" position="replace">
|
||||||
|
<field name="related_product"/>
|
||||||
|
<field name="part_number"/>
|
||||||
|
<field name="part_name"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_purchase_request_line_tree_sf" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.request.line.sf.tree</field>
|
||||||
|
<field name="model">purchase.request.line</field>
|
||||||
|
<field name="inherit_id" ref="purchase_request.purchase_request_line_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='requested_by']" position="replace">
|
||||||
|
<field name="supply_method"/>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='assigned_to']" position="replace">
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='name']" position="attributes">
|
||||||
|
<attribute name="invisible">True</attribute>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='supplier_id']" position="after">
|
||||||
|
<field name="requested_by" widget="many2one_avatar_user"/>
|
||||||
|
<field name="assigned_to" widget="many2one_avatar_user"/>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='purchased_qty']" position="attributes">
|
||||||
|
<attribute name="string">采购数量</attribute>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='purchase_state']" position="attributes">
|
||||||
|
<attribute name="string">订单状态</attribute>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='product_id']" position="after">
|
||||||
|
<field name="related_product"/>
|
||||||
|
<field name="part_number"/>
|
||||||
|
<field name="part_name"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_purchase_request_line_search_sf" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.request.line.sf.search</field>
|
||||||
|
<field name="model">purchase.request.line</field>
|
||||||
|
<field name="inherit_id" ref="purchase_request.purchase_request_line_search" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='product_id']" position="after">
|
||||||
|
<field name="related_product"/>
|
||||||
|
<field name="part_number"/>
|
||||||
|
<field name="part_name"/>
|
||||||
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
Reference in New Issue
Block a user