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 Apr 12, 2017
2 parents 38ca9bd + 461e8b4 commit 03ed634
Show file tree
Hide file tree
Showing 20 changed files with 443 additions and 57 deletions.
6 changes: 6 additions & 0 deletions core/static/src/less/core.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.o_form_view .o_form_field_pdfviewer {
width: 100%;
height: 450px;
border: 0;
margin-top: 10px;
}
7 changes: 5 additions & 2 deletions finance/models/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def compute_balance(self):
:return:
"""
lines = self.env['voucher.line'].search(
[('account_id', '=', self.id)])
[('account_id', '=', self.id),
('voucher_id.state', '=', 'done')])
self.balance = sum((line.debit - line.credit) for line in lines)

name = fields.Char(u'名称', required="1")
Expand Down Expand Up @@ -457,7 +458,9 @@ def name_get(self):
"""
result = []
for line in self:
account_name = line.code + ' ' + line.name + ' ' + str(line.balance)
account_name = line.code + ' ' + line.name
if line.env.context.get('show_balance'):
account_name += ' ' + str(line.balance)
result.append((line.id, account_name))
return result

Expand Down
22 changes: 20 additions & 2 deletions finance/tests/test_finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,26 @@ def setUp(self):

def test_name_get(self):
name = self.cash.name_get()
real_name = '%s %s %s' % (self.cash.code, self.cash.name, self.cash.balance)
real_name = '%s %s' % (self.cash.code, self.cash.name)
self.assertTrue(name[0][1] == real_name)

# def test_name_get_in_voucher(self):
# """仅在凭证界面选择科目时显示出余额"""
# voucher = self.env.ref('finance.voucher_1')
# self.env['voucher.line'].create({
# 'voucher_id': voucher.id,
# 'name': u'测试科目显示出余额',
# 'account_id': self.cash.with_context({'show_balance': True}).id, # 给该字段传context没有成功
# })
# name = self.cash.name_get()
# real_name = '%s %s %s' % (self.cash.code, self.cash.name, self.cash.balance)
# self.assertTrue(name[0][1] == real_name)

def test_name_search(self):
'''会计科目按名字和编号搜索'''
result = self.env['finance.account'].name_search('库存现金')
real_result = [(self.cash.id,
self.cash.code + ' ' + self.cash.name + ' ' + str(self.cash.balance))]
self.cash.code + ' ' + self.cash.name)]

self.assertEqual(result, real_result)

Expand All @@ -286,6 +298,12 @@ def test_get_max_code_account(self):
account = self.env['finance.account']
account.get_max_code_account()

def test_compute_balance(self):
"""计算会计科目的当前余额"""
self.cash.compute_balance()
self.assertEqual(self.cash.balance, 0)


class test_voucher_template_wizard(TransactionCase):
def setUp(self):
super(test_voucher_template_wizard, self).setUp()
Expand Down
4 changes: 3 additions & 1 deletion finance/views/finance_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
<field name="line_ids" context="{'line_ids':line_ids}">
<tree editable='bottom'>
<field name='name'/>
<field name='account_id' options="{'no_create': True}"/>
<field name='account_id' options="{'no_create': True}"
context="{'show_balance':True}"
/>
<field name='partner_id' options="{'no_open': True, 'no_create': True}"
domain="[('name','=',False)]"/>
<field name='goods_id' groups='finance.group_account_goods'
Expand Down
2 changes: 2 additions & 0 deletions good_process/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import mail_thread
20 changes: 20 additions & 0 deletions good_process/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
{
"name": "good_process",
"version": '11.11',
"author": '',
"website": "http://www.osbzr.com",
"category": "Generic Modules",
"description": """
""",
"data": [
'good_process.xml',
'security/ir.model.access.csv'
],
"depends":[
'core',
],
'qweb': [
'static/src/xml/*.xml',
],
}
69 changes: 69 additions & 0 deletions good_process/good_process.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0"?>
<openerp>
<data>
<template id="assets_backend" name="Core" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/good_process/static/src/js/good_process.js"></script>
</xpath>
</template>
<record id='good_process_process_form' model='ir.ui.view'>
<field name='name'>good_process.process</field>
<field name='model'>good_process.process</field>
<field name='arch' type='xml'>
<form string='审批'>
<group>
<field name='model_id'/>
<field name='is_department_approve'/>
</group>
<field name='line_ids'>
<tree editable='TOP' string='审批'>
<field name='sequence'/>
<field name='group_id'/>
<field name='is_all_approve' />
</tree>
</field>
</form>
</field>
</record>
<record id='good_process_process_tree' model='ir.ui.view'>
<field name='name'>attribute value value tree</field>
<field name='model'>good_process.process</field>
<field name='arch' type='xml'>
<tree string='审批'>
<field name='model_id'/>
<field name='is_department_approve'/>
</tree>
</field>
</record>

<record id='good_process_process_action' model='ir.actions.act_window'>
<field name='name'>审批设置</field>
<field name='res_model'>good_process.process</field>
<field name='view_mode'>tree,form</field>
</record>
<menuitem id='good_process_process_menu' name='审批设置' action='good_process_process_action'
parent='core.system_menu' sequence='20'/>



<record id='good_process_approver_tree' model='ir.ui.view'>
<field name='name'>good_process.approver</field>
<field name='model'>good_process.approver</field>
<field name='arch' type='xml'>
<tree string='审批人' editable="bottom">
<field name='model'/>
<field name='res_id'/>
<field name='group_id'/>
<field name='user_id'/>
<field name='sequence'/>
</tree>
</field>
</record>

<record id='good_process_approver_action' model='ir.actions.act_window'>
<field name='name'>审批人</field>
<field name='res_model'>good_process.approver</field>
<field name='view_mode'>tree</field>
</record>
</data>
</openerp>
150 changes: 150 additions & 0 deletions good_process/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.exceptions import ValidationError

class mail_thread(models.AbstractModel):
_inherit = 'mail.thread'
_to_approver_ids = fields.One2many('good_process.approver', 'res_id',
domain=lambda self: [('model', '=', self._name)], auto_join=True, string='待审批人')

def get_groups(self, model_name):
process_rows = self.env['good_process.process'].search([('model_id.model', '=', model_name)])
groups = []
if process_rows:
[groups.append((line.group_id, line.sequence)) for line in self.env['good_process.process_line'].search(
[('process_id', '=', process_rows.id)], order='sequence')]
return groups

def get_users(self, groups):
users = []
sequence_dict = {}
for group, sequence in groups:
[(users.append(user),sequence_dict.update({user.id:sequence}))
for user in group.users]

return users, sequence_dict

def _add_approver(self, thread_row, model_name):

groups = self.get_groups(model_name)
users, user_sequence_dict= self.get_users(groups)
approver_rows = []
[approver_rows.append(self.env['good_process.approver'].create(
{'user_id': user.id,
'res_id': thread_row.id,
'sequence': user_sequence_dict.get(user.id),
'model': thread_row._name})) for user in users]
return [{'id': row.id, 'display_name': row.user_id.name} for row in approver_rows]

# def constract_message(self, name, group):
# message = ""
# user_row = self.env['res.users'].browse(self.env.uid)
# for group in user_row.group_ids:
# if group.category_id.name == 'Gooderp':
# message = "%s %s %s" % (name, group.name, user_row.name)
# return message

def good_approver_send_message(self, active_id, active_model, group, message):
mode_row = self.env[active_model].browse(active_id)
user_row = self.env['res.users'].browse(self.env.uid)
message_text = u"%s %s %s %s" % (group.name, user_row.name, message, mode_row.name)
mode_row.message_post(message_text, subtype='mail.mt_comment')

@api.model
def approve(self, active_id, active_model):
group, user_ids, is_all_approve, sequence = self.get_user_group(active_model)
return_vals = self._remove_approver(active_id, active_model, user_ids, is_all_approve, sequence)
if return_vals:
self.good_approver_send_message(active_id, active_model, group, u'同意')
else:
return_vals = u'这个单子您还没必要审批!'
return return_vals

@api.model
def refused(self, active_id, active_model):
group, user_ids, is_all_approve, sequence = self.get_user_group(active_model)
mode_row = self.env[active_model].browse(active_id)
approver_rows = self.env['good_process.approver'].search([('model', '=', active_model),
('res_id', '=', active_id)])
if approver_rows:
approver_rows.unlink()
self.good_approver_send_message(active_id, active_model, group, u'拒绝')
retturn_vals = self._add_approver(mode_row, active_model)
else:
retturn_vals = u'已经通过能拒绝!'
return retturn_vals


@api.model
def create(self, vals):
thread_row = super(mail_thread, self).create(vals)
self._add_approver(thread_row, self._name)
return thread_row

def get_user_group(self, active_model):
process_rows = self.env['good_process.process'].search([('model_id.model', '=', active_model)])
group_dict = {}
[group_dict.update({line.group_id.id: (line.is_all_approve, line.sequence)})
for line in self.env['good_process.process_line'].search(
[('process_id', '=', process_rows.id)], order='sequence')]
group = self.env['res.groups'].search([('id', 'in', group_dict.keys()),
('users', 'in', self.env.uid)])
return (group, [user.id for user in group.users],
group_dict.get(group.id, [False, 0])[0], group_dict.get(group.id, [False,0])[1])

def get_remove_approver(self, thread_row, user_ids, is_all_approve, sequence):
remove_approve, return_vals = [], []
group_id = False
for approver in thread_row._to_approver_ids:
if approver.user_id.id in user_ids:
if approver.user_id.id == self.env.uid or group_id == approver.group_id.id:
remove_approve.append(approver)
return_vals.append(approver.id)
group_id = approver.group_id.id
elif approver.sequence != sequence and not return_vals:
break
if return_vals and is_all_approve:
break
return return_vals, remove_approve

@api.model
def _remove_approver(self, active_id, active_model, user_ids, is_all_approve, sequence):
return_vals = False
if active_id:
thread_row = self.env[active_model].browse(active_id)
return_vals, remove_approvers = self.get_remove_approver(thread_row,
user_ids, is_all_approve, sequence)
if remove_approvers:
[approver.unlink() for approver in remove_approvers]
return return_vals

class approver(models.Model):
_name = 'good_process.approver'
_rec_name = 'user_id'
_order = 'sequence'
model = fields.Char('Related Document Model', index=True)
res_id = fields.Many2one('Related Document ID', index=True)
group_id = fields.Many2one('res.groups', string='用户组')
user_id = fields.Many2one('res.users', string='用户')
sequence = fields.Integer(string='顺序')
_approver_num = fields.Integer(string='总审批人数')

@api.model_cr
def init(self):
self._cr.execute("""SELECT indexname FROM pg_indexes WHERE indexname = 'good_process_approver_model_res_id_idx'""")
if not self._cr.fetchone():
self._cr.execute("""CREATE INDEX good_process_approver_model_res_id_idx ON good_process_approver (model, res_id)""")

class process(models.Model):
_name = 'good_process.process'
_rec_name = 'model_id'
model_id = fields.Many2one('ir.model')
is_department_approve = fields.Boolean(string='部门经理审批')
line_ids = fields.One2many('good_process.process_line', 'process_id', string='审批组')

class process_line(models.Model):
_name = 'good_process.process_line'
sequence = fields.Integer(string='序号')
group_id = fields.Many2one('res.groups', string='序号')
is_all_approve = fields.Boolean(string='是否全部审批')
process_id = fields.Many2one('process')
5 changes: 5 additions & 0 deletions good_process/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
acceces_good_process_approver_all,acceces_good_process_approver_all,model_good_process_approver,,1,1,1,1
acceces_good_process_process_all,acceces_good_process_process_all,model_good_process_process,,1,1,1,1
acceces_good_process_process_line_all,acceces_good_process_process_line_all,model_good_process_process_line,,1,1,1,1

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added good_process/static/description/设置.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 03ed634

Please sign in to comment.