@@ -31,3 +31,46 @@ def _search_default_journal(self, journal_types):
3131 if receipt_journal :
3232 journal = receipt_journal
3333 return journal
34+
35+ def _get_journal_types (self , move_type ):
36+ if move_type in self .get_sale_types (include_receipts = True ):
37+ journal_types = ["sale" ]
38+ elif move_type in self .get_purchase_types (include_receipts = True ):
39+ journal_types = ["purchase" ]
40+ else :
41+ journal_types = self .env .context .get (
42+ "default_move_journal_types" , ["general" ]
43+ )
44+ return journal_types
45+
46+ @api .model
47+ def _update_receipts_journal (self , vals_list ):
48+ """
49+ Update `vals_list` in place to set journal_id to the receipt journal
50+ when move_type is receipt.
51+
52+ Model defaults are also considered it move_type or journal_id
53+ are not in a `vals_list`.
54+ """
55+ defaults = self .default_get (["journal_id" , "move_type" ])
56+ default_journal = defaults .get ("journal_id" )
57+ default_move_type = defaults .get ("move_type" )
58+ for vals in vals_list :
59+ move_type = vals .get ("move_type" , default_move_type )
60+ if move_type in ("in_receipt" , "out_receipt" ):
61+ selected_journal_id = vals .get ("journal_id" , default_journal )
62+ selected_journal = self .env ["account.journal" ].browse (
63+ selected_journal_id
64+ )
65+ if not selected_journal .receipts :
66+ journal_types = self ._get_journal_types (move_type )
67+ receipt_journal = self ._search_default_receipt_journal (
68+ journal_types
69+ )
70+ if receipt_journal :
71+ vals ["journal_id" ] = receipt_journal .id
72+
73+ @api .model_create_multi
74+ def create (self , vals_list ):
75+ self ._update_receipts_journal (vals_list )
76+ return super ().create (vals_list )
0 commit comments