[FIX] account,sale: Sale person and team

When creating a Vendor Bill, the default Sales Team & Person of the company is
assigned to the Vendor Bill. The field isn't even displayed, it's hidden, you
can only display it with Studio and can't even change it.

The fact is : purchases and sales are two completely different roles and
business in companies. This has the indirect consequence that any user that
follows the default Sales Team will get notified of any new Vendor Bill created
in Accounting, which he very likely does not need/want to see.

This PR correct that by adding a condition on the filling of these fields. These
 fields will be filled when the move is a sale document.

closes odoo/odoo#120628

Task-id: 3279233
Related: odoo/enterprise#44034
Signed-off-by: Florian Gilbert (flg) <flg@odoo.com>
This commit is contained in:
Maximilien (malb)
2023-07-13 16:52:46 +02:00
parent 929f6288ec
commit ea8acc17b4
4 changed files with 13 additions and 23 deletions
-2
View File
@@ -109,7 +109,6 @@ class AccountChartTemplate(models.AbstractModel):
'demo_invoice_5': {
'move_type': 'in_invoice',
'partner_id': 'base.res_partner_12',
'invoice_user_id': 'base.user_demo',
'invoice_payment_term_id': 'account.account_payment_term_end_following_month',
'invoice_date': time.strftime('%Y-%m-01'),
'delivery_date': time.strftime('%Y-%m-01'),
@@ -120,7 +119,6 @@ class AccountChartTemplate(models.AbstractModel):
},
'demo_invoice_extract': {
'move_type': 'in_invoice',
'invoice_user_id': 'base.user_demo',
},
'demo_invoice_equipment_purchase': {
'move_type': 'in_invoice',
+12 -1
View File
@@ -521,7 +521,8 @@ class AccountMove(models.Model):
comodel_name='res.users',
copy=False,
tracking=True,
default=lambda self: self.env.user,
compute='_compute_invoice_default_sale_person',
store=True,
)
# Technical field used to fit the generic behavior in mail templates.
user_id = fields.Many2one(string='User', related='invoice_user_id')
@@ -628,6 +629,16 @@ class AccountMove(models.Model):
# COMPUTE METHODS
# -------------------------------------------------------------------------
@api.depends('move_type')
def _compute_invoice_default_sale_person(self):
# We want to modify the sale person only when we don't have one and if the move type corresponds to this condition
# If the move doesn't correspond, we remove the sale person
for move in self:
if move.is_sale_document(include_receipts=True):
move.invoice_user_id = move.invoice_user_id or self.env.user
else:
move.invoice_user_id = False
def _compute_payment_reference(self):
for move in self.filtered(lambda m: (
m.state == 'posted'
-19
View File
@@ -332,7 +332,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_1': {
"ref": "test_invoice_1: Invoice to gritti support service, vat 21",
"partner_id": self.res_partner_gritti_mono,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": "out_invoice",
"invoice_date": "2021-03-01",
@@ -344,7 +343,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_2': {
"ref": "test_invoice_2: Invoice to CMR with vat 21, 27 and 10,5",
"partner_id": self.res_partner_cmr,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": "out_invoice",
"invoice_date": "2021-03-05",
@@ -358,7 +356,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_3': {
"ref": "test_invoice_3: Invoice to ADHOC with vat cero and 21",
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-01",
@@ -371,7 +368,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_4': {
'ref': 'test_invoice_4: Invoice to ADHOC with vat exempt and 21',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-01",
@@ -384,7 +380,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_5': {
'ref': 'test_invoice_5: Invoice to ADHOC with all type of taxes',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -402,7 +397,6 @@ class TestAr(AccountTestInvoicingCommon):
'ref': 'test_invoice_6: Invoice to cerro castor, fiscal position changes taxes to exempt',
"partner_id": self.res_partner_cerrocastor,
"journal_id": self.sale_expo_journal_ri,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-03",
@@ -421,7 +415,6 @@ class TestAr(AccountTestInvoicingCommon):
'ref': 'test_invoice_7: Export invoice to expresso, fiscal position changes tax to exempt (type 4 because it have services)',
"partner_id": self.res_partner_expresso,
"journal_id": self.sale_expo_journal_ri,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-03",
@@ -439,7 +432,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_8': {
'ref': 'test_invoice_8: Invoice to consumidor final',
"partner_id": self.partner_cf,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -451,7 +443,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_10': {
'ref': 'test_invoice_10; Invoice to ADHOC in USD and vat 21',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -464,7 +455,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_11': {
'ref': 'test_invoice_11: Invoice to ADHOC with many lines in order to prove rounding error, with 4 decimals of precision for the currency and 2 decimals for the product the error apperar',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -479,7 +469,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_12': {
'ref': 'test_invoice_12: Invoice to ADHOC with many lines in order to test rounding error, it is required to use a 4 decimal precision in prodct in order to the error occur',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -494,7 +483,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_13': {
'ref': 'test_invoice_13: Invoice to ADHOC with many lines in order to test zero amount invoices y rounding error. it is required to set the product decimal precision to 4 and change 260.59 for 260.60 in order to reproduce the error',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -514,7 +502,6 @@ class TestAr(AccountTestInvoicingCommon):
'ref': 'test_invoice_14: Export invoice to expresso, fiscal position changes tax to exempt (type 1 because only products)',
"partner_id": self.res_partner_expresso,
"journal_id": self.sale_expo_journal_ri,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-20",
@@ -528,7 +515,6 @@ class TestAr(AccountTestInvoicingCommon):
'ref': 'test_invoice_15: Export invoice to expresso, fiscal position changes tax to exempt (type 2 because only service)',
"partner_id": self.res_partner_expresso,
"journal_id": self.sale_expo_journal_ri,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-20",
@@ -542,7 +528,6 @@ class TestAr(AccountTestInvoicingCommon):
'ref': 'test_invoice_16: Export invoice to expresso, fiscal position changes tax to exempt (type 1 because it have products only, used to test refund of expo)',
"partner_id": self.res_partner_expresso,
"journal_id": self.sale_expo_journal_ri,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-22",
@@ -555,7 +540,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_17': {
'ref': 'test_invoice_17: Invoice to ADHOC with 100%% of discount',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -567,7 +551,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_18': {
'ref': 'test_invoice_18: Invoice to ADHOC with 100%% of discount and with different VAT aliquots',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -581,7 +564,6 @@ class TestAr(AccountTestInvoicingCommon):
'test_invoice_19': {
'ref': 'test_invoice_19: Invoice to ADHOC with multiple taxes and perceptions',
"partner_id": self.res_partner_adhoc,
"invoice_user_id": invoice_user_id,
"invoice_payment_term_id": payment_term_id,
"move_type": 'out_invoice',
"invoice_date": "2021-03-13",
@@ -598,7 +580,6 @@ class TestAr(AccountTestInvoicingCommon):
with Form(self.env['account.move'].with_context(default_move_type=values['move_type'])) as invoice_form:
invoice_form.ref = values['ref']
invoice_form.partner_id = values['partner_id']
invoice_form.invoice_user_id = values['invoice_user_id']
invoice_form.invoice_payment_term_id = values['invoice_payment_term_id']
if not use_current_date:
invoice_form.invoice_date = values['invoice_date']
+1 -1
View File
@@ -35,7 +35,7 @@ class AccountMove(models.Model):
@api.depends('invoice_user_id')
def _compute_team_id(self):
for move in self:
if not move.invoice_user_id.sale_team_id:
if not move.invoice_user_id.sale_team_id or not move.is_sale_document(include_receipts=True):
continue
move.team_id = self.env['crm.team']._get_default_team_id(
user_id=move.invoice_user_id.id,