Skip to content

Commit 8e4c47a

Browse files
committed
Merge PR OCA#919 into 13.0
Signed-off-by pedrobaeza
2 parents 4820b5d + 9a57173 commit 8e4c47a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

account_global_discount/models/account_move.py

+19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
class AccountMove(models.Model):
1010
_inherit = "account.move"
1111

12+
# HACK: Looks like UI doesn't behave well with Many2many fields and
13+
# negative groups when the same field is shown. In this case, we want to
14+
# show the readonly version to any not in the global discount group.
15+
# TODO: Check if it's fixed in future versions
16+
global_discount_ids_readonly = fields.Many2many(
17+
string="Invoice Global Discounts (readonly)",
18+
related="global_discount_ids",
19+
readonly=True,
20+
)
1221
global_discount_ids = fields.Many2many(
1322
comodel_name="global.discount",
1423
column1="invoice_id",
@@ -262,6 +271,16 @@ def _compute_amount(self):
262271
for record in self:
263272
record._compute_amount_one()
264273

274+
@api.model_create_multi
275+
def create(self, vals_list):
276+
"""If we create the invoice with the discounts already set like from
277+
a sales order, we must compute the global discounts as well"""
278+
moves = super().create(vals_list)
279+
move_with_global_discounts = moves.filtered("global_discount_ids")
280+
for move in move_with_global_discounts:
281+
move.with_context(check_move_validity=False)._onchange_invoice_line_ids()
282+
return moves
283+
265284

266285
class AccountMoveLine(models.Model):
267286
_inherit = "account.move.line"

account_global_discount/views/account_invoice_views.xml

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
name="global_discount_ids"
1515
widget="many2many_tags"
1616
placeholder="Discounts..."
17+
groups="base_global_discount.group_global_discount"
18+
/>
19+
<field
20+
string="Invoice Global Discounts"
21+
name="global_discount_ids_readonly"
22+
widget="many2many_tags"
23+
readonly="1"
24+
groups="!base_global_discount.group_global_discount"
1725
/>
1826
</xpath>
1927
<field name="amount_untaxed" position="before">

account_global_discount/views/global_discount_views.xml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
id="menu_account_global_discount"
3535
action="base_global_discount.action_global_discount_tree"
3636
name="Global Discounts"
37+
groups="base_global_discount.group_global_discount"
3738
parent="account.account_management_menu"
3839
/>
3940
</odoo>

0 commit comments

Comments
 (0)