|
9 | 9 | class AccountMove(models.Model):
|
10 | 10 | _inherit = "account.move"
|
11 | 11 |
|
| 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 | + ) |
12 | 21 | global_discount_ids = fields.Many2many(
|
13 | 22 | comodel_name="global.discount",
|
14 | 23 | column1="invoice_id",
|
@@ -262,6 +271,16 @@ def _compute_amount(self):
|
262 | 271 | for record in self:
|
263 | 272 | record._compute_amount_one()
|
264 | 273 |
|
| 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 | + |
265 | 284 |
|
266 | 285 | class AccountMoveLine(models.Model):
|
267 | 286 | _inherit = "account.move.line"
|
|
0 commit comments