203 lines
8.6 KiB
Python
203 lines
8.6 KiB
Python
import datetime
|
|
import base64
|
|
from odoo import models, fields, api, _
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class ReSaleOrder(models.Model):
|
|
_inherit = 'sale.order'
|
|
|
|
deadline_of_delivery = fields.Date('订单交期', tracking=True)
|
|
person_of_delivery = fields.Char('交货人')
|
|
telephone_of_delivery = fields.Char('交货人电话号码')
|
|
address_of_delivery = fields.Char('交货人地址')
|
|
payments_way = fields.Selection([('现结', '现结'), ('月结', '月结')], '结算方式', default='现结', tracking=True)
|
|
pay_way = fields.Selection([('转账', '转账'), ('微信', '微信'), ('支付宝', '支付宝')], '支付方式')
|
|
check_status = fields.Selection([('pending', '待审核'), ('approved', '已审核'), ('fail', '不通过')], '审核状态')
|
|
schedule_status = fields.Selection(
|
|
[('to schedule', '待排程'), ('to process', '待加工'), ('to deliver', '待发货'), ('to receive', '待收货'),
|
|
('received', '已收货')],
|
|
'进度状态')
|
|
payment_term_id = fields.Many2one(
|
|
comodel_name='account.payment.term',
|
|
string="交付条件",
|
|
compute='_compute_payment_term_id',
|
|
store=True, readonly=False, precompute=True, check_company=True, tracking=True,
|
|
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
|
|
remark = fields.Text('备注')
|
|
|
|
# 业务平台分配工厂后在智能工厂先创建销售订单
|
|
def sale_order_create(self, company_id, delivery_name, delivery_telephone, delivery_address,
|
|
deadline_of_delivery, payments_way, pay_way):
|
|
now_time = datetime.datetime.now()
|
|
partner = self.get_customer()
|
|
order_id = self.env['sale.order'].sudo().create({
|
|
'company_id': company_id.id,
|
|
'date_order': now_time,
|
|
'name': self.env['ir.sequence'].next_by_code('sale.order', sequence_date=now_time),
|
|
'partner_id': partner.id,
|
|
'check_status': 'approved',
|
|
'state': 'draft',
|
|
'person_of_delivery': delivery_name,
|
|
'telephone_of_delivery': delivery_telephone,
|
|
'address_of_delivery': delivery_address,
|
|
'deadline_of_delivery': deadline_of_delivery,
|
|
'payments_way': payments_way,
|
|
'pay_way': pay_way,
|
|
})
|
|
return order_id
|
|
|
|
def write(self, vals):
|
|
if self.env.user.has_group('sf_base.group_sale_director'):
|
|
if vals.get('check_status'):
|
|
if vals['check_status'] in ('pending', False):
|
|
vals['check_status'] = 'approved'
|
|
return super().write(vals)
|
|
|
|
# 提交
|
|
def submit(self):
|
|
self.check_status = 'pending'
|
|
|
|
def get_customer(self):
|
|
customer = self.env['res.partner'].search([('name', '=', '业务平台')])
|
|
if customer:
|
|
return customer
|
|
else:
|
|
partner = self.env['res.partner'].create({'name': '业务平台'})
|
|
return partner
|
|
|
|
# 业务平台分配工厂时在创建完产品后再创建销售明细信息
|
|
def sale_order_create_line(self, product, item):
|
|
vals = {
|
|
'order_id': self.id,
|
|
'product_id': product.id,
|
|
'name': '%s/%s/%s/%s/±%s/%s' % (
|
|
product.model_long, product.model_width, product.model_height, product.model_volume,
|
|
product.model_machining_precision,
|
|
product.materials_id.name),
|
|
'price_unit': product.list_price,
|
|
'product_uom_qty': item['number'],
|
|
'model_glb_file': base64.b64decode(item['model_file']),
|
|
}
|
|
return self.env['sale.order.line'].create(vals)
|
|
|
|
|
|
class ResaleOrderLine(models.Model):
|
|
_inherit = 'sale.order.line'
|
|
|
|
model_glb_file = fields.Binary('模型的glb文件')
|
|
check_status = fields.Selection(related='order_id.check_status')
|
|
|
|
|
|
class RePurchaseOrder(models.Model):
|
|
_inherit = 'purchase.order'
|
|
|
|
check_status = fields.Selection([('pending', '待审核'), ('approved', '已审核'), ('fail', '不通过')], '审核状态')
|
|
remark = fields.Text('备注')
|
|
|
|
def write(self, vals):
|
|
if self.env.user.has_group('sf_base.group_purchase_director'):
|
|
if vals.get('check_status'):
|
|
if vals['check_status'] in ('pending', False):
|
|
vals['check_status'] = 'approved'
|
|
return super().write(vals)
|
|
|
|
def button_confirm(self):
|
|
self.check_status = 'pending'
|
|
res = super().button_confirm()
|
|
return res
|
|
|
|
|
|
class ResPartnerToSale(models.Model):
|
|
_inherit = 'res.partner'
|
|
|
|
purchase_user_id = fields.Many2one('res.users', '采购员')
|
|
|
|
@api.constrains('name')
|
|
def _check_name(self):
|
|
obj = self.sudo().search([('name', '=', self.name), ('id', '!=', self.id)])
|
|
if obj:
|
|
raise UserError('该名称已存在,请重新输入')
|
|
|
|
@api.constrains('vat')
|
|
def _check_vat(self):
|
|
obj = self.sudo().search([('vat', '=', self.vat), ('id', '!=', self.id)])
|
|
if obj:
|
|
raise UserError('该税ID已存在,请重新输入')
|
|
|
|
@api.constrains('email')
|
|
def _check_email(self):
|
|
if self.customer_rank > 0:
|
|
obj = self.sudo().search([('email', '=', self.email), ('id', '!=', self.id)])
|
|
if obj:
|
|
raise UserError('该邮箱已存在,请重新输入')
|
|
|
|
@api.model
|
|
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
|
|
if self._context.get('is_customer'):
|
|
if self.env.user.has_group('sf_base.group_sale_director'):
|
|
domain = [('customer_rank', '>', 0)]
|
|
elif self.env.user.has_group('sf_base.group_sale_salemanager'):
|
|
customer = self.env['res.partner'].search(
|
|
[('customer_rank', '>', 0), ('user_id', '=', self.env.user.id)])
|
|
if customer:
|
|
ids = [t.id for t in customer]
|
|
domain = [('id', 'in', ids)]
|
|
else:
|
|
domain = [('id', '=', False)]
|
|
return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
|
|
elif self._context.get('is_supplier'):
|
|
if self.env.user.has_group('sf_base.group_purchase_director'):
|
|
domain = [('supplier_rank', '>', 0)]
|
|
elif self.env.user.has_group('sf_base.group_purchase'):
|
|
customer = self.env['res.partner'].search(
|
|
[('supplier_rank', '>', 0), ('user_id', '=', self.env.user.id)])
|
|
if customer:
|
|
ids = [t.id for t in customer]
|
|
domain = [('id', 'in', ids)]
|
|
else:
|
|
domain = [('id', '=', False)]
|
|
return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
|
|
return super()._name_search(name, args, operator, limit, name_get_uid)
|
|
|
|
@api.onchange('user_id')
|
|
def _get_salesman(self):
|
|
if self.customer_rank > 0:
|
|
if self.env.user.has_group('sf_base.group_sale_salemanager'):
|
|
self.user_id = self.env.user.id
|
|
|
|
@api.onchange('purchase_user_id')
|
|
def _get_purchaseman(self):
|
|
if self.supplier_rank > 0:
|
|
if self.env.user.has_group('sf_base.group_purchase'):
|
|
self.purchase_user_id = self.env.user.id
|
|
|
|
|
|
class ResUserToSale(models.Model):
|
|
_inherit = 'res.users'
|
|
|
|
@api.model
|
|
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
|
|
if self._context.get('is_sale'):
|
|
if self.env.user.has_group('sf_base.group_sale_director'):
|
|
domain = []
|
|
elif self.env.user.has_group('sf_base.group_sale_salemanager'):
|
|
if self.id != self.env.user.id:
|
|
domain = [('id', '=', self.id)]
|
|
else:
|
|
domain = [('id', '=', self.env.user.id)]
|
|
return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
|
|
elif self._context.get('supplier_rank'):
|
|
if self.env.user.has_group('sf_base.group_purchase_director'):
|
|
domain = [('supplier_rank', '>', 0)]
|
|
elif self.env.user.has_group('sf_base.group_purchase'):
|
|
supplier = self.env['res.partner'].search(
|
|
[('supplier_rank', '>', 0), ('purchase_user_id', '=', self.env.user.id)])
|
|
if supplier:
|
|
ids = [t.id for t in supplier]
|
|
domain = [('id', 'in', ids)]
|
|
else:
|
|
domain = [('id', '=', False)]
|
|
return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
|
|
return super()._name_search(name, args, operator, limit, name_get_uid)
|