'date_order': fields.datetime('Order Date', readonly=True, select=True),
'user_id': fields.many2one('res.users', 'Salesman', help="Person who uses the the cash register. It can be a reliever, a student or an interim employee."),
'amount_tax': fields.function(_amount_all, string='Taxes', digits_compute=dp.get_precision('Account'), multi='all'),
- 'amount_total': fields.function(_amount_all, string='Total', multi='all'),
+ 'amount_total': fields.function(_amount_all, string='Total', digits_compute=dp.get_precision('Account'), multi='all'),
'amount_paid': fields.function(_amount_all, string='Paid', states={'draft': [('readonly', False)]}, readonly=True, digits_compute=dp.get_precision('Account'), multi='all'),
- 'amount_return': fields.function(_amount_all, 'Returned', digits_compute=dp.get_precision('Account'), multi='all'),
+ 'amount_return': fields.function(_amount_all, string='Returned', digits_compute=dp.get_precision('Account'), multi='all'),
'lines': fields.one2many('pos.order.line', 'order_id', 'Order Lines', states={'draft': [('readonly', False)]}, readonly=True, copy=True),
'statement_ids': fields.one2many('account.bank.statement.line', 'pos_statement_id', 'Payments', states={'draft': [('readonly', False)]}, readonly=True),
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, states={'draft': [('readonly', False)]}, readonly=True),
options = options || {};
this.pos = options.pos || (parent ? parent.pos : undefined);
this.pos_widget = options.pos_widget || (parent ? parent.pos_widget : undefined);
- this.build_currency_template();
},
- build_currency_template: function(){
+ format_currency: function(amount,precision){
+ var currency = (this.pos && this.pos.currency) ? this.pos.currency : {symbol:'$', position: 'after', rounding: 0.01, decimals: 2};
+ var decimals = currency.decimals;
- if(this.pos && this.pos.currency){
- this.currency = this.pos.currency;
- }else{
- this.currency = {symbol: '$', position: 'after', rounding: 0.01};
+ if (precision && (typeof this.pos.dp[precision]) !== undefined) {
+ decimals = this.pos.dp[precision];
}
- var decimals = Math.max(0,Math.ceil(Math.log(1.0 / this.currency.rounding) / Math.log(10)));
-
+ this.format_currency_no_symbol = function(amount){
+ amount = round_pr(amount,this.currency.rounding);
+ amount = amount.toFixed(decimals);
+ return amount;
+ };
+
- this.format_currency = function(amount){
- if(typeof amount === 'number'){
- amount = Math.round(amount*100)/100;
- amount = amount.toFixed(decimals);
- }
- if(this.currency.position === 'after'){
- return amount + ' ' + (this.currency.symbol || '');
- }else{
- return (this.currency.symbol || '') + ' ' + amount;
- }
- };
+ if (typeof amount === 'number') {
+ amount = round_di(amount,decimals).toFixed(decimals);
+ }
+ if (currency.position === 'after') {
+ return amount + ' ' + (currency.symbol || '');
+ } else {
+ return (currency.symbol || '') + ' ' + amount;
+ }
},
show: function(){
this.$el.removeClass('oe_hidden');
raise KarmaError('Not enough karma to accept or refuse an answer')
# update karma except for self-acceptance
mult = 1 if vals['is_correct'] else -1
- for post in self.browse(cr, uid, ids, context=context):
- if vals['is_correct'] != post.is_correct and post.create_uid.id != uid:
- self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id], post.forum_id.karma_gen_answer_accepted * mult, context=context)
- self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [uid], post.forum_id.karma_gen_answer_accept * mult, context=context)
- if any(key not in ['state', 'active', 'is_correct', 'closed_uid', 'closed_date', 'closed_reason_id'] for key in vals.keys()) and any(not post.can_edit for post in posts):
+ for post in self:
+ if vals['is_correct'] != post.is_correct and post.create_uid.id != self._uid:
+ post.create_uid.sudo().add_karma(post.forum_id.karma_gen_answer_accepted * mult)
+ self.env.user.sudo().add_karma(post.forum_id.karma_gen_answer_accept * mult)
+ if any(key not in ['state', 'active', 'is_correct', 'closed_uid', 'closed_date', 'closed_reason_id'] for key in vals.keys()) and any(not post.can_edit for post in self):
raise KarmaError('Not enough karma to edit a post.')
- res = super(Post, self).write(cr, uid, ids, vals, context=context)
+ res = super(Post, self).write(vals)
# if post content modify, notify followers
if 'content' in vals or 'name' in vals:
- for post in posts:
+ for post in self:
if post.parent_id:
body, subtype = _('Answer Edited'), 'website_forum.mt_answer_edit'
- obj_id = post.parent_id.id
+ obj_id = post.parent_id
else:
body, subtype = _('Question Edited'), 'website_forum.mt_question_edit'
- obj_id = post.id
- self.message_post(cr, uid, obj_id, body=body, subtype=subtype, context=context)
+ obj_id = post
+ obj_id.message_post(body=body, subtype=subtype)
return res
-
- def reopen(self, cr, uid, ids, context=None):
- if any(post.parent_id or post.state != 'close'
- for post in self.browse(cr, uid, ids, context=context)):
+ @api.multi
+ def reopen(self):
+ if any(post.parent_id or post.state != 'close' for post in self):
return False
- reason_offensive = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_7')
- reason_spam = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_8')
- for post in self.browse(cr, uid, ids, context=context):
- if post.closed_reason_id.id in (reason_offensive, reason_spam):
+ reason_offensive = self.env.ref('website_forum.reason_7')
+ reason_spam = self.env.ref('website_forum.reason_8')
+ for post in self:
+ if post.closed_reason_id in (reason_offensive, reason_spam):
_logger.info('Upvoting user <%s>, reopening spam/offensive question',
- post.create_uid.login)
+ post.create_uid)
# TODO: in master, consider making this a tunable karma parameter
- self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id],
- post.forum_id.karma_gen_question_downvote * -5,
- context=context)
- self.pool['forum.post'].write(cr, SUPERUSER_ID, ids, {'state': 'active'}, context=context)
+ post.create_uid.sudo().add_karma(post.forum_id.karma_gen_question_downvote * -5)
- def close(self, cr, uid, ids, reason_id, context=None):
- if any(post.parent_id for post in self.browse(cr, uid, ids, context=context)):
+ self.sudo().write({'state': 'active'})
+
+ @api.multi
+ def close(self, reason_id):
+ if any(post.parent_id for post in self):
return False
- reason_offensive = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_7')
- reason_spam = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_8')
+ reason_offensive = self.env.ref('website_forum.reason_7').id
+ reason_spam = self.env.ref('website_forum.reason_8').id
if reason_id in (reason_offensive, reason_spam):
- for post in self.browse(cr, uid, ids, context=context):
+ for post in self:
_logger.info('Downvoting user <%s> for posting spam/offensive contents',
- post.create_uid.login)
+ post.create_uid)
# TODO: in master, consider making this a tunable karma parameter
- self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id],
- post.forum_id.karma_gen_question_downvote * 5,
- context=context)
+ post.create_uid.sudo().add_karma(post.forum_id.karma_gen_question_downvote * 5)
- self.pool['forum.post'].write(cr, uid, ids, {
+ self.write({
'state': 'close',
- 'closed_uid': uid,
+ 'closed_uid': self._uid,
'closed_date': datetime.today().strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT),
'closed_reason_id': reason_id,
- }, context=context)
+ })
+ return True
- def unlink(self, cr, uid, ids, context=None):
- posts = self.browse(cr, uid, ids, context=context)
- if any(not post.can_unlink for post in posts):
+ @api.multi
+ def unlink(self):
+ if any(not post.can_unlink for post in self):
raise KarmaError('Not enough karma to unlink a post')
# if unlinking an answer with accepted answer: remove provided karma
- for post in posts:
+ for post in self:
if post.is_correct:
- self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id], post.forum_id.karma_gen_answer_accepted * -1, context=context)
- self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [uid], post.forum_id.karma_gen_answer_accept * -1, context=context)
- return super(Post, self).unlink(cr, uid, ids, context=context)
-
- def vote(self, cr, uid, ids, upvote=True, context=None):
- Vote = self.pool['forum.post.vote']
- vote_ids = Vote.search(cr, uid, [('post_id', 'in', ids), ('user_id', '=', uid)], context=context)
+ post.create_uid.sudo().add_karma(post.forum_id.karma_gen_answer_accepted * -1)
+ self.env.user.sudo().add_karma(post.forum_id.karma_gen_answer_accepted * -1)
+ return super(Post, self).unlink()
+
+ @api.multi
+ def vote(self, upvote=True):
+ Vote = self.env['forum.post.vote']
+ vote_ids = Vote.search([('post_id', 'in', self._ids), ('user_id', '=', self._uid)])
new_vote = '1' if upvote else '-1'
voted_forum_ids = set()
if vote_ids: