[IMP] sale,account: automatic salesteam selection

This commit adds the automatic selection of the salesteam
for sale.order and account.invoice objects so that changing
the salesperson will automatically changes the team if the new
salesperson has one. If they are not part of a team, the current
value is left unchanged.

This will avoid having the manually correct the salesteam
every time the salesperson is modified.

task-1984950 closes-#33618

closes odoo/odoo#33618

Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
Mitali Patel
2019-06-24 12:37:33 +00:00
parent 34c4b3ad8a
commit 242be00429
2 changed files with 14 additions and 3 deletions
+5
View File
@@ -46,6 +46,11 @@ class AccountInvoice(models.Model):
company = self.company_id or self.env.company
self.comment = company.with_context(lang=self.partner_id.lang).invoice_terms or (self._origin.company_id == company and self.comment)
@api.onchange('user_id')
def onchange_user_id(self):
if self.user_id and self.user_id.sale_team_id:
self.team_id = self.user_id.sale_team_id
@api.multi
def _prepare_refund(self, invoice, date_invoice=None, date=None, description=None, journal_id=None):
values = super(AccountInvoice, self)._prepare_refund(invoice, date_invoice, date, description, journal_id)
+9 -3
View File
@@ -303,20 +303,26 @@ class SaleOrder(models.Model):
return
addr = self.partner_id.address_get(['delivery', 'invoice'])
partner_user = self.partner_id.user_id or self.partner_id.commercial_partner_id.user_id
values = {
'pricelist_id': self.partner_id.property_product_pricelist and self.partner_id.property_product_pricelist.id or False,
'payment_term_id': self.partner_id.property_payment_term_id and self.partner_id.property_payment_term_id.id or False,
'partner_invoice_id': addr['invoice'],
'partner_shipping_id': addr['delivery'],
'user_id': self.partner_id.user_id.id or self.partner_id.commercial_partner_id.user_id.id or self.env.uid
'user_id': partner_user.id or self.env.uid
}
if self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') and self.env.company.invoice_terms:
values['note'] = self.with_context(lang=self.partner_id.lang).env.company.invoice_terms
# Use team of saleman before to fallback on team of partner.
values['team_id'] = self.partner_id.user_id and self.partner_id.user_id.sale_team_id.id or self.partner_id.team_id.id
# Use team of salesman if any otherwise leave as-is
values['team_id'] = partner_user.team_id.id if partner_user and partner_user.team_id else self.team_id
self.update(values)
@api.onchange('user_id')
def onchange_user_id(self):
if self.user_id and self.user_id.sale_team_id:
self.team_id = self.user_id.sale_team_id
@api.onchange('partner_id')
def onchange_partner_id_warning(self):
if not self.partner_id: