Skip to content

Commit

Permalink
Merge remote-tracking branch 'osbzr/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodERPJeff committed Jun 14, 2018
2 parents 69ecd43 + 5eff152 commit f1f55cd
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 59 deletions.
12 changes: 7 additions & 5 deletions buy/models/buy_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ def _default_warehouse_dest(self):
def _get_paid_amount(self):
'''计算购货订单付款/退款状态'''
if not self.invoice_by_receipt: # 分期付款时
money_orders = self.env['money.order'].search([
('buy_id', '=', self.id),
('reconciled', '!=', 0),
money_invoices = self.env['money.invoice'].search([
('name', '=', self.name),
('state', '=', 'done')])
self.paid_amount = sum([order.amount for order in money_orders])
self.paid_amount = sum([invoice.reconciled for invoice in money_invoices])
else:
receipts = self.env['buy.receipt'].search([('order_id', '=', self.id)])
# 购货订单上输入预付款时
Expand All @@ -105,7 +104,9 @@ def _compute_receipt(self):
@api.depends('receipt_ids')
def _compute_invoice(self):
for order in self:
order.invoice_ids = order.receipt_ids.mapped('invoice_id')
money_invoices = self.env['money.invoice'].search([
('name', '=', order.name)])
order.invoice_ids = not money_invoices and order.receipt_ids.mapped('invoice_id') or money_invoices + order.receipt_ids.mapped('invoice_id')
order.invoice_count = len(order.invoice_ids.ids)

@api.one
Expand Down Expand Up @@ -729,5 +730,6 @@ def request_payment(self):
'reconciled': 0,
'to_reconcile': self.amount_money,
'state': 'draft',
'buy_id': self.buy_id.id,
})
self.date_application = datetime.now()
51 changes: 51 additions & 0 deletions money/tests/test_reconcile_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,57 @@ def test_reconcile_order(self):
with self.assertRaises(UserError):
reconcile_pay_to_pay_done.reconcile_order_done()

def test_reconcile_order_draft_adv_pay_to_get(self):
''' Test: reconcile_order_draft: adv_pay_to_get '''
# 预收冲应收
reconcile = self.env.ref('money.reconcile_adv_pay_to_get')
reconcile.partner_id = self.env.ref('core.jd').id
reconcile.onchange_partner_id()
reconcile.advance_payment_ids.to_reconcile = 300.0
reconcile.advance_payment_ids.this_reconcile = 300.0
reconcile.reconcile_order_done()
reconcile.reconcile_order_draft()

# 核销单已撤销,不能再次撤销 报错
with self.assertRaises(UserError):
reconcile.reconcile_order_draft()

def test_reconcile_order_draft_adv_get_to_pay(self):
''' Test: reconcile_order_draft: adv_get_to_pay '''
self.env.ref('money.pay_2000').money_order_done()
# 预付冲应付
reconcile = self.env.ref('money.reconcile_adv_get_to_pay')
reconcile.partner_id = self.env.ref('core.lenovo').id
reconcile.onchange_partner_id()
reconcile.advance_payment_ids.to_reconcile = 600.0
reconcile.advance_payment_ids.this_reconcile = 600.0
reconcile.reconcile_order_done()
reconcile.reconcile_order_draft()

# 反核销时,金额不相同 报错
reconcile.reconcile_order_done()
with self.assertRaises(UserError):
reconcile.payable_source_ids.this_reconcile = 666.0
reconcile.reconcile_order_draft()

def test_reconcile_order_draft_pay_to_pay(self):
''' Test: reconcile_order_draft: pay_to_pay '''
# 应收转应收
reconcile = self.env.ref('money.reconcile_pay_to_pay')
reconcile.partner_id = self.env.ref('core.lenovo').id
reconcile.onchange_partner_id()
reconcile.payable_source_ids.to_reconcile = 300.0
reconcile.payable_source_ids.this_reconcile = 300.0
reconcile.reconcile_order_done()
reconcile.reconcile_order_draft()

# 业务伙伴和转入往来单位不能相同 报错
reconcile.reconcile_order_done()
with self.assertRaises(UserError):
reconcile.to_partner_id = self.env.ref('core.lenovo').id
reconcile.onchange_partner_id()
reconcile.reconcile_order_draft()

def test_onchange_partner_id(self):
'''核销单onchange_partner_id()'''
# onchange_partner_id改变partner_id
Expand Down
1 change: 1 addition & 0 deletions staff_hire/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
# only loaded in demonstration mode
'demo': [
'tests/demo.xml',
],
'installable': True,
'application': False,
Expand Down
54 changes: 10 additions & 44 deletions staff_hire/models/staff_hire.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,14 @@ class hire_applicant(models.Model):
_rec_name = 'partner_name'

def _default_stage_id(self):
if self._context.get('default_job_id'):
ids = self.env['staff.hire.stage'].search([
'|',
('job_id', '=', False),
('job_id', '=', self._context['default_job_id']),
('fold', '=', False)
], order='sequence asc', limit=1).ids
if ids:
return ids[0]
'''返回阶段的默认值'''
ids = self.env['staff.hire.stage'].search([
('job_id', '=', False),
], order='sequence asc', limit=1).ids
if ids:
return ids[0]
return False

def _default_company_id(self):
company_id = False
if self._context.get('default_department_id'):
department = self.env['staff.department'].browse(self._context['default_department_id'])
company_id = department.company_id.id
if not company_id:
company_id = self.env['res.company']._company_default_get('hire.applicant')
return company_id

active = fields.Boolean(u"有效", default=True, help=u"如果“有效”字段设为false,它对信息进行隐藏但不删除它。")
note = fields.Text(u"备注")
email_from = fields.Char(u"Email", size=128, help=u"这些人将收到电子邮件")
Expand All @@ -83,10 +71,8 @@ def _default_company_id(self):
domain=[('type', '=', 'hire_categ')],
context={'type': 'hire_categ'}
)
company_id = fields.Many2one('res.company', u"公司", default=_default_company_id)
company_id = fields.Many2one('res.company', u"公司", default=lambda self: self.env['res.company']._company_default_get())
user_id = fields.Many2one('res.users', u"负责人", track_visibility="onchange", default=lambda self: self.env.uid)
# date_closed = fields.Datetime(u"关闭日期", readonly=True, index=True)
# date_open = fields.Datetime(u"开启日期", readonly=True, index=True)
date_last_stage_update = fields.Datetime(u"最终阶段更新时间", index=True, default=fields.Datetime.now)
date_action = fields.Date(u"下步计划日期")
title_action = fields.Char(u"下步计划", size=64)
Expand Down Expand Up @@ -141,12 +127,14 @@ def _read_group_stage_ids(self, stages, domain, order):

@api.onchange('job_id')
def onchange_job_id(self):
'''选择职位,带出部门、负责人及阶段'''
vals = self._onchange_job_id_internal(self.job_id.id)
self.department_id = vals['value']['department_id']
self.user_id = vals['value']['user_id']
self.stage_id = vals['value']['stage_id']

def _onchange_job_id_internal(self, job_id):
'''选择职位具体实现'''
department_id = False
user_id = False
stage_id = self.stage_id.id
Expand All @@ -169,33 +157,11 @@ def _onchange_job_id_internal(self, job_id):
'stage_id': stage_id
}}

def _onchange_stage_id_internal(self, stage_id):
if not stage_id:
return {'value': {}}
stage = self.env['staff.hire.stage'].browse(stage_id)
if stage.fold:
return {'value': {'date_closed': fields.datetime.now()}}
return {'value': {'date_closed': False}}

@api.model
def create(self, vals):
if vals.get('department_id') and not self._context.get('default_department_id'):
self = self.with_context(default_department_id=vals.get('department_id'))
if vals.get('job_id') or self._context.get('default_job_id'):
job_id = vals.get('job_id') or self._context.get('default_job_id')
for key, value in self._onchange_job_id_internal(job_id)['value'].iteritems():
if key not in vals:
vals[key] = value
if 'stage_id' in vals:
vals.update(self._onchange_stage_id_internal(vals.get('stage_id'))['value'])
return super(hire_applicant, self.with_context(mail_create_nolog=True)).create(vals)

@api.multi
def write(self, vals):
# stage_id: track last stage before update
if 'stage_id' in vals:
vals['date_last_stage_update'] = fields.Datetime.now()
vals.update(self._onchange_stage_id_internal(vals.get('stage_id'))['value'])
for applicant in self:
vals['last_stage_id'] = applicant.stage_id.id
res = super(hire_applicant, self).write(vals)
Expand Down Expand Up @@ -252,7 +218,7 @@ def _track_subtype(self, init_values):

@api.multi
def create_employee_from_applicant(self):
""" Create an staff from the hire.applicants """
""" 创建员工 """
staff = False
for applicant in self:
if not applicant.salary_proposed:
Expand Down
1 change: 0 additions & 1 deletion staff_hire/report/hire_report_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<field name="stage_id"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="date_create"/>
<!--<field name="date_closed"/>-->
</group>
<group expand="1" string="Group By">
<filter string="Responsible" name='User' context="{'group_by':'user_id'}"/>
Expand Down
2 changes: 2 additions & 0 deletions staff_hire/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import test_staff_hire
12 changes: 12 additions & 0 deletions staff_hire/tests/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<openerp>
<data>
<!--招聘申请-->
<record id="hire_lucy" model="hire.applicant">
<field name="partner_name">Lucy</field>
<field name="partner_mobile">18899996666</field>
<field name='job_id' ref='staff.staff_job_1'/>
<field name="salary_proposed">3000</field>
</record>
</data>
</openerp>
40 changes: 40 additions & 0 deletions staff_hire/tests/test_staff_hire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError


class TestHireApplicant(TransactionCase):

def setUp(self):
super(TestHireApplicant, self).setUp()
self.hire = self.env.ref('staff_hire.hire_lucy')

def test_default_stage_id(self):
'''返回阶段的默认值'''
hire = self.env['hire.applicant'].create({
'partner_name': u'小赵',
'partner_mobile': '188188188',
'job_id': self.env.ref('staff.staff_job_1').id,
})

def test_onchange_job_id(self):
'''选择职位,带出部门、负责人及阶段'''
self.hire.onchange_job_id()
self.assertTrue(self.hire.department_id, self.env.ref('staff.department_1'))

def test_create_employee_from_applicant(self):
'''创建员工'''
self.hire.create_employee_from_applicant()
self.assertTrue(self.hire.staff_id.name, 'Lucy')
self.hire.action_get_created_employee()
# 期望薪资未输入时应报错
hire = self.hire.copy()
hire.salary_proposed = 0
with self.assertRaises(UserError):
hire.create_employee_from_applicant()

def test_action_get_created_employee(self):
'''跳到新创建的员工界面'''
self.hire.create_employee_from_applicant()
action = self.hire.action_get_created_employee()
self.assertTrue(action['res_id'], self.hire.staff_id.id)
14 changes: 10 additions & 4 deletions task/views/views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,16 @@
<field name="arch" type="xml">
<form string="timeline">
<sheet>
<field name="task_id" placeholder="任务" domain="[('user_id', 'in', [uid, False]),('status.state', '!=', 'done')]"/>
<field name="just_done" placeholder="具体内容"/>
<field name="hours" placeholder="小时数" groups='task.group_task_hours'/>
<field name="create_date" string='创建时间' readonly='1'/>
<group>
<field name="task_id" domain="[('user_id', 'in', [uid, False]),('status.state', '!=', 'done')]"/>
<field name="just_done"/>
<field name="hours" groups='task.group_task_hours' class="oe_inline"/>
<field name='next_action'/>
<field name='next_datetime'/>
<field name='set_status'/>
<field name='user_id'/>
<field name="create_date" string="创建时间" readonly='1'/>
</group>
</sheet>
</form>
</field>
Expand Down
8 changes: 4 additions & 4 deletions tax_invoice_in/models/tax_invoice_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def _compute_tax_amount(self):
total = 0
for line in self.line_ids:
if line.is_deductible:
total = total + 0
total += 0
else:
total = total +line.invoice_tax
total = total + line.invoice_tax
self.tax_amount = total

#由发票生成采购订单
Expand Down Expand Up @@ -101,7 +101,7 @@ def tax_invoice_draft(self):
def tax_invoice_done(self):
for line in self.line_ids:
if not line.buy_id:
raise UserError(u'发票号码:%s未下推生成采购订单!'%line.name)
raise UserError(u'发票号码:%s未下推生成采购订单!' % line.name)
self.state = 'done'


Expand All @@ -125,7 +125,7 @@ def create_cn_account_invoice(self):
table = xls_data.sheets()[0]
ncows = table.nrows
ncols = 0
colnames = table.row_values(0)
colnames = table.row_values(0)
list =[]
#数据读入,过滤没有开票日期的行
for rownum in range(1,ncows):
Expand Down
Binary file modified tax_invoice_in/tests/201805_3.xls
Binary file not shown.
9 changes: 9 additions & 0 deletions tax_invoice_in/tests/test_tax_invoice_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def test_invoice_to_buy(self):
self.env.ref('core.supplier_category_1').id)
self.tax_invoice_in.invoice_to_buy()

# test: _compute_tax_amount
for line in self.tax_invoice_in.line_ids:
line.is_deductible = True
break

def test_write(self):
''' Test: Write '''
self.tax_invoice_in.name = self.env.ref('finance.period_201604').id

def test_tax_invoice_done(self):
''' Test: tax_invoice_done '''
self.invoice_wizard.with_context({'active_id': self.tax_invoice_in.id}).create_cn_account_invoice()
Expand Down
2 changes: 1 addition & 1 deletion tax_invoice_out/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
import test_out
import test_tax_invoice_out
Binary file modified tax_invoice_out/tests/sell.xlsx
Binary file not shown.
File renamed without changes.

0 comments on commit f1f55cd

Please sign in to comment.