Skip to content

Commit

Permalink
[MERGE] forward port branch 11.0 up to e3658d6
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Jun 12, 2018
2 parents 9a6ef3c + e3658d6 commit af18537
Show file tree
Hide file tree
Showing 68 changed files with 542 additions and 127 deletions.
13 changes: 10 additions & 3 deletions addons/account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def _get_sequence_prefix(self):
""" computes the prefix of the number that will be assigned to the first invoice/bill/refund of a journal, in order to
let the user manually change it.
"""
if not self.env.user._is_admin():
if not self.env.user._is_system():
for invoice in self:
invoice.sequence_number_next_prefix = False
invoice.sequence_number_next = ''
Expand Down Expand Up @@ -1519,6 +1519,13 @@ def get_invoice_line_account(self, type, product, fpos, company):
return accounts['income']
return accounts['expense']

def _set_currency(self):
company = self.invoice_id.company_id
currency = self.invoice_id.currency_id
if company and currency:
if company.currency_id != currency:
self.price_unit = self.price_unit * currency.with_context(dict(self._context or {}, date=self.invoice_id.date_invoice)).rate

def _set_taxes(self):
""" Used in on_change to set taxes and price."""
if self.invoice_id.type in ('out_invoice', 'out_refund'):
Expand All @@ -1537,8 +1544,10 @@ def _set_taxes(self):
prec = self.env['decimal.precision'].precision_get('Product Price')
if not self.price_unit or float_compare(self.price_unit, self.product_id.standard_price, precision_digits=prec) == 0:
self.price_unit = fix_price(self.product_id.standard_price, taxes, fp_taxes)
self._set_currency()
else:
self.price_unit = fix_price(self.product_id.lst_price, taxes, fp_taxes)
self._set_currency()

@api.onchange('product_id')
def _onchange_product_id(self):
Expand Down Expand Up @@ -1587,8 +1596,6 @@ def _onchange_product_id(self):
domain['uom_id'] = [('category_id', '=', product.uom_id.category_id.id)]

if company and currency:
if company.currency_id != currency:
self.price_unit = self.price_unit * currency.with_context(dict(self._context or {}, date=self.invoice_id.date_invoice)).rate

if self.uom_id and self.uom_id.id != product.uom_id.id:
self.price_unit = product.uom_id._compute_price(self.price_unit, self.uom_id)
Expand Down
2 changes: 1 addition & 1 deletion addons/account/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ResConfigSettings(models.TransientModel):
'account.journal',
related='company_id.currency_exchange_journal_id',
string="Exchange Gain or Loss Journal",
domain=[('type', '=', 'general')],
domain="[('company_id', '=', company_id), ('type', '=', 'general')]",
help='The accounting journal where automatic exchange differences will be registered')
has_chart_of_accounts = fields.Boolean(compute='_compute_has_chart_of_accounts', string='Company has a chart of accounts')
chart_template_id = fields.Many2one('account.chart.template', string='Template',
Expand Down
12 changes: 7 additions & 5 deletions addons/account/views/account_journal_dashboard_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,16 @@
<span><t t-esc="dashboard.account_balance"/></span>
</div>
</div>
<div class="row" name="latest_statement" t-if="dashboard.last_balance != dashboard.account_balance">
<div class="col-xs-7">
<t t-if="dashboard.last_balance != dashboard.account_balance">
<div class="row" name="latest_statement">
<div class="col-xs-7">
<span title="Latest Statement">Latest Statement</span>
</div>
<div class="col-xs-5 text-right">
</div>
<div class="col-xs-5 text-right">
<span><t t-esc="dashboard.last_balance"/></span>
</div>
</div>
</div>
</t>
</div>
</t>
<t t-name="JournalBodySalePurchase" id="account.JournalBodySalePurchase">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def import_file(self):
# Create the bank statements
statement_ids, notifications = self._create_bank_statements(stmts_vals)
# Now that the import worked out, set it as the bank_statements_source of the journal
journal.bank_statements_source = 'file_import'
if journal.bank_statements_source != 'file_import':
# Use sudo() because only 'account.group_account_manager'
# has write access on 'account.journal', but 'account.group_account_user'
# must be able to import bank statement files
journal.sudo().bank_statements_source = 'file_import'
# Finally dispatch to reconciliation interface
action = self.env.ref('account.action_bank_reconcile_bank_statements')
return {
Expand Down
5 changes: 4 additions & 1 deletion addons/board/static/src/js/favorite_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ FavoriteMenu.include({
})
.then(function (r) {
if (r) {
self.do_notify(_.str.sprintf(_t("'%s' added to dashboard"), name), '');
self.do_notify(
_.str.sprintf(_t("'%s' added to dashboard"), name),
_t('Please refresh your browser for the changes to take effect.')
);
} else {
self.do_warn(_t("Could not add filter to dashboard"));
}
Expand Down
2 changes: 2 additions & 0 deletions addons/crm/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def _onchange_partner_id(self):
@api.model
def _onchange_user_values(self, user_id):
""" returns new values when user_id has changed """
if not user_id:
return {}
if user_id and self._context.get('team_id'):
team = self.env['crm.team'].browse(self._context['team_id'])
if user_id in team.member_ids.ids:
Expand Down
2 changes: 1 addition & 1 deletion addons/event/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ResPartner(models.Model):

def _compute_event_count(self):
for partner in self:
partner.event_count = self.env['event.event'].search_count([('registration_ids.partner_id', 'child_of', partner.ids)])
partner.event_count = self.env['event.event'].sudo().search_count([('registration_ids.partner_id', 'child_of', partner.ids)])

@api.multi
def action_event_view(self):
Expand Down
2 changes: 1 addition & 1 deletion addons/event/report/event_event_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<img t-att-src="'data:image/png;base64,%s' % to_text(o.event_id.organizer_id.company_id.logo_web)" style="max-height:1cm; max-width:4cm;"/>
</span>
<h5 t-field="o.event_id.name"/>
<h5>( <i class="fa fa-clock-o"></i> <span itemprop="startDate" t-field="o.event_id.date_begin" t-options='{"hide_seconds": True}'> </span> <i>to</i> <span itemprop="endDate" t-field="o.event_id.date_end" t-options='{"hide_seconds": True}'> </span> )</h5>
<h5>( <i class="fa fa-clock-o"></i> <span itemprop="startDate" t-field="o.event_id.with_context(tz=o.event_id.date_tz).date_begin" t-options='{"hide_seconds": True}'> </span> <i>to</i> <span itemprop="endDate" t-field="o.event_id.with_context(tz=o.event_id.date_tz).date_end" t-options='{"hide_seconds": True}'> </span> )</h5>
</div>
<div class="row">
<div class="col-xs-12 text-center" id="o_event_name">
Expand Down
2 changes: 1 addition & 1 deletion addons/hr_holidays/models/hr_leave.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _default_employee(self):
number_of_days = fields.Float('Number of Days', compute='_compute_number_of_days', store=True, track_visibility='onchange')
meeting_id = fields.Many2one('calendar.event', string='Meeting')

parent_id = fields.Many2one('hr.leave', string='Parent')
parent_id = fields.Many2one('hr.leave', string='Parent', copy=False)
linked_request_ids = fields.One2many('hr.leave', 'parent_id', string='Linked Requests')
department_id = fields.Many2one('hr.department', string='Department', readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]})
category_id = fields.Many2one('hr.employee.category', string='Employee Tag', readonly=True,
Expand Down
8 changes: 6 additions & 2 deletions addons/mail/static/src/js/systray.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,19 @@ var MessagingMenu = Widget.extend({
if (channelID === 'channel_inbox') {
var resID = $(event.currentTarget).data('res_id');
var resModel = $(event.currentTarget).data('res_model');
if (resModel && resID) {
if (resModel && resModel !== 'mail.channel' && resID) {
this.do_action({
type: 'ir.actions.act_window',
res_model: resModel,
views: [[false, 'form']],
res_id: resID
});
} else {
this.do_action('mail.mail_channel_action_client_chat', {clear_breadcrumbs: true})
var clientChatOptions = {clear_breadcrumbs: true};
if (resModel && resModel === 'mail.channel' && resID) {
clientChatOptions.active_id = resID;
}
this.do_action('mail.mail_channel_action_client_chat', clientChatOptions)
.then(function () {
self.trigger_up('hide_home_menu'); // we cannot 'go back to previous page' otherwise
core.bus.trigger('change_menu_section', self.call('chat_manager', 'getDiscussMenuID'));
Expand Down
2 changes: 1 addition & 1 deletion addons/mass_mailing/static/src/js/mass_mailing.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FieldTextHtml.include({
var datarecord = this._super();
if (this.model === 'mail.mass_mailing') {
// these fields can potentially get very long, let's remove them
datarecord = _.omit(datarecord, ['mailing_domain', 'contact_list_ids', 'body_html']);
datarecord = _.omit(datarecord, ['mailing_domain', 'contact_list_ids', 'body_html', 'attachment_ids']);
}
return datarecord;
},
Expand Down
2 changes: 1 addition & 1 deletion addons/mass_mailing_event_track/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def action_mass_mailing_track_speakers(self):
view_mode='form',
target='current',
context=dict(
default_mailing_model=self.env.ref('website_event_track.model_event_track').id,
default_mailing_model_id=self.env.ref('website_event_track.model_event_track').id,
default_mailing_domain="[('event_id', 'in', %s), ('stage_id.is_cancel', '!=', True)]" % self.ids,
),
)
Expand Down
2 changes: 2 additions & 0 deletions addons/mrp/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def onchange_product_uom_id(self):
def onchange_product_tmpl_id(self):
if self.product_tmpl_id:
self.product_uom_id = self.product_tmpl_id.uom_id.id
if self.product_id.product_tmpl_id != self.product_tmpl_id:
self.product_id = False

@api.onchange('routing_id')
def onchange_routing_id(self):
Expand Down
1 change: 1 addition & 0 deletions addons/mrp/models/mrp_workorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def record_production(self):
move_line = production_move.move_line_ids.filtered(lambda x: x.lot_id.id == self.final_lot_id.id)
if move_line:
move_line.product_uom_qty += self.qty_producing
move_line.qty_done += self.qty_producing
else:
move_line.create({'move_id': production_move.id,
'product_id': production_move.product_id.id,
Expand Down
7 changes: 7 additions & 0 deletions addons/mrp/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class StockMove(models.Model):
order_finished_lot_ids = fields.Many2many('stock.production.lot', compute='_compute_order_finished_lot_ids')
finished_lots_exist = fields.Boolean('Finished Lots Exist', compute='_compute_order_finished_lot_ids')

def _unreserve_initial_demand(self, new_move):
# If you were already putting stock.move.lots on the next one in the work order, transfer those to the new move
self.filtered(lambda m: m.production_id or m.raw_material_production_id)\
.mapped('move_line_ids')\
.filtered(lambda ml: ml.qty_done == 0.0)\
.write({'move_id': new_move, 'product_uom_qty': 0})

@api.depends('active_move_line_ids.qty_done', 'active_move_line_ids.product_uom_id')
def _compute_done_quantity(self):
super(StockMove, self)._compute_done_quantity()
Expand Down
55 changes: 34 additions & 21 deletions addons/mrp/report/mrp_bom_structure_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,49 @@
class BomStructureReport(models.AbstractModel):
_name = 'report.mrp.mrp_bom_structure_report'

def get_children(self, object, level=0):
@api.model
def _get_child_vals(self, record, level, qty, uom):
"""Get bom.line values.
:param record: mrp.bom.line record
:param level: level of recursion
:param qty: quantity of the product
:param uom: unit of measurement of a product
"""
child = {
'pname': record.product_id.name_get()[0][1],
'pcode': record.product_id.default_code,
'puom': record.product_uom_id,
'uname': record.product_uom_id.name,
'level': level,
'code': record.bom_id.code,
}
qty_per_bom = record.bom_id.product_qty
if uom:
if uom != record.bom_id.product_uom_id:
qty = uom._compute_quantity(qty, record.bom_id.product_uom_id)
child['pqty'] = (record.product_qty * qty) / qty_per_bom
else:
# for the first case, the ponderation is right
child['pqty'] = (record.product_qty * qty)
return child

def get_children(self, records, level=0):
result = []

def _get_rec(object, level, qty=1.0, uom=False):
for l in object:
res = {}
res['pname'] = l.product_id.name_get()[0][1]
res['pcode'] = l.product_id.default_code
qty_per_bom = l.bom_id.product_qty
if uom:
if uom != l.bom_id.product_uom_id:
qty = uom._compute_quantity(qty, l.bom_id.product_uom_id)
res['pqty'] = (l.product_qty *qty)/ qty_per_bom
else:
#for the first case, the ponderation is right
res['pqty'] = (l.product_qty *qty)
res['puom'] = l.product_uom_id
res['uname'] = l.product_uom_id.name
res['level'] = level
res['code'] = l.bom_id.code
result.append(res)
def _get_rec(records, level, qty=1.0, uom=False):
for l in records:
child = self._get_child_vals(l, level, qty, uom)
result.append(child)
if l.child_line_ids:
if level < 6:
level += 1
_get_rec(l.child_line_ids, level, qty=res['pqty'], uom=res['puom'])
_get_rec(l.child_line_ids, level, qty=child['pqty'], uom=child['puom'])
if level > 0 and level < 6:
level -= 1
return result

children = _get_rec(object, level)
children = _get_rec(records, level)

return children

Expand Down
2 changes: 1 addition & 1 deletion addons/mrp/views/mrp_workorder_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<label for="duration"/>
<div>
<button style="pointer-events: none;" class="oe_inline label label-default">
<field name="duration" widget="mrp_time_counter"/>
<field name="duration" widget="mrp_time_counter" help="Time the currently logged user spent on this workorder."/>
</button>
</div>
</group>
Expand Down
13 changes: 11 additions & 2 deletions addons/payment_authorize/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def _authorize_generate_hashing(self, values):
@api.multi
def authorize_form_generate_values(self, values):
self.ensure_one()
# State code is only supported in US, use state name by default
# See https://developer.authorize.net/api/reference/
state = values['partner_state'].name if values.get('partner_state') else ''
if values.get('partner_country') and values.get('partner_country') == self.env.ref('base.us', False):
state = values['partner_state'].code if values.get('partner_state') else ''
billing_state = values['billing_partner_state'].name if values.get('billing_partner_state') else ''
if values.get('billing_partner_country') and values.get('billing_partner_country') == self.env.ref('base.us', False):
billing_state = values['billing_partner_state'].code if values.get('billing_partner_state') else ''

base_url = self.env['ir.config_parameter'].get_param('web.base.url')
authorize_tx_values = dict(values)
temp_authorize_tx_values = {
Expand All @@ -83,7 +92,7 @@ def authorize_form_generate_values(self, values):
'first_name': values.get('partner_first_name'),
'last_name': values.get('partner_last_name'),
'phone': values.get('partner_phone'),
'state': values.get('partner_state') and values['partner_state'].code or '',
'state': state,
'billing_address': values.get('billing_partner_address'),
'billing_city': values.get('billing_partner_city'),
'billing_country': values.get('billing_partner_country') and values.get('billing_partner_country').name or '',
Expand All @@ -92,7 +101,7 @@ def authorize_form_generate_values(self, values):
'billing_first_name': values.get('billing_partner_first_name'),
'billing_last_name': values.get('billing_partner_last_name'),
'billing_phone': values.get('billing_partner_phone'),
'billing_state': values.get('billing_partner_state') and values['billing_partner_state'].code or '',
'billing_state': billing_state,
}
temp_authorize_tx_values['returndata'] = authorize_tx_values.pop('return_url', '')
temp_authorize_tx_values['x_fp_hash'] = self._authorize_generate_hashing(temp_authorize_tx_values)
Expand Down
4 changes: 2 additions & 2 deletions addons/point_of_sale/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def _confirm_orders(self):
paid=order.amount_paid,
))
order.action_pos_order_done()
orders = session.order_ids.filtered(lambda order: order.state in ['invoiced', 'done'])
orders.sudo()._reconcile_payments()
orders_to_reconcile = session.order_ids.filtered(lambda order: order.state in ['invoiced', 'done'] and order.partner_id)
orders_to_reconcile.sudo()._reconcile_payments()

config_id = fields.Many2one(
'pos.config', string='Point of Sale',
Expand Down
12 changes: 12 additions & 0 deletions addons/point_of_sale/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def _onchange_sale_ok(self):
self.available_in_pos = False


class ProductProduct(models.Model):
_inherit = 'product.product'

@api.multi
def unlink(self):
product_ctx = dict(self.env.context or {}, active_test=False)
if self.env['pos.session'].search_count([('state', '!=', 'closed')]):
if self.with_context(product_ctx).search_count([('id', 'in', self.ids), ('product_tmpl_id.available_in_pos', '=', True)]):
raise UserError(_('You cannot delete a product saleable in point of sale while a session is still opened.'))
return super(ProductProduct, self).unlink()


class ProductUomCateg(models.Model):
_inherit = 'product.uom.categ'

Expand Down
3 changes: 2 additions & 1 deletion addons/point_of_sale/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ exports.Orderline = Backbone.Model.extend({
this.set_unit_price(this.product.get_price(this.order.pricelist, this.get_quantity()));
this.order.fix_tax_included_price(this);
}
this.trigger('change', this);
},
// return the quantity of product
get_quantity: function(){
Expand Down Expand Up @@ -2124,7 +2125,7 @@ exports.Order = Backbone.Model.extend({
company_registry: company.company_registry,
contact_address: company.partner_id[1],
vat: company.vat,
vat_label: company.country.vat_label,
vat_label: company.country && company.country.vat_label || '',
name: company.name,
phone: company.phone,
logo: this.pos.company_logo_base64,
Expand Down
Loading

0 comments on commit af18537

Please sign in to comment.