Skip to content

Commit

Permalink
[FIX] purchase_request : Multi-company sequence bug
Browse files Browse the repository at this point in the history
There is a bug that occurs with this module when using multi-company, the sequence is only allowed for the first company while you cannot create new records on the rest
  • Loading branch information
aliiahmed20 committed Jan 25, 2025
1 parent 3e40e46 commit ec899f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions purchase_request/data/purchase_request_sequence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<field name="code">purchase.request</field>
<field name="prefix">PR</field>
<field name="padding">5</field>
<field name="company_id" eval="False"/>
</record>
</odoo>
6 changes: 5 additions & 1 deletion purchase_request/models/purchase_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _get_default_requested_by(self):

@api.model
def _get_default_name(self):
return self.env["ir.sequence"].next_by_code("purchase.request")
return self.env["ir.sequence"].with_company(self.env.company).sudo().next_by_code("purchase.request")

@api.model
def _default_picking_type(self):
Expand Down Expand Up @@ -239,7 +239,11 @@ def _get_partner_id(self, request):
def create(self, vals_list):
for vals in vals_list:
if vals.get("name", _("New")) == _("New"):
<<<<<<< Updated upstream
vals["name"] = self._get_default_name()
=======
vals['name'] = self.env['ir.sequence'].with_company(vals.get('company_id')).next_by_code('purchase.request') or _("New")
>>>>>>> Stashed changes
requests = super().create(vals_list)
for vals, request in zip(vals_list, requests, strict=True):
if vals.get("assigned_to"):
Expand Down

0 comments on commit ec899f3

Please sign in to comment.