Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow producer to edit their products on hubs' orders #13113

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def is_hub
sells == 'any'
end

def is_producer
def is_producer_only
is_primary_producer && sells == 'none'
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ def can_manage_orders?
# any of order distributors allow them to edit their orders.
def can_manage_line_items_in_orders?
@can_manage_line_items_in_orders ||= begin
has_any_producer = enterprises.any?(&:is_producer)
has_producer_editable_orders = Spree::Order.editable_by_producers(enterprises).exists?
has_any_producer && has_producer_editable_orders
return unless enterprises.any?(&:is_producer_only)

Spree::Order.editable_by_producers(enterprises).exists?
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/models/enterprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1013,25 +1013,25 @@ def should_have_enterprise_relationship(opts = {})
end
end

describe "#is_producer" do
describe "#is_producer_only" do
context "when enterprise is_primary_producer and sells none" do
it "returns true" do
enterprise = build(:supplier_enterprise)
expect(enterprise.is_producer).to be true
expect(enterprise.is_producer_only).to be true
end
end

context "when enterprise is_primary_producer and sells any" do
it "returns false" do
enterprise = build(:enterprise, is_primary_producer: true, sells: "any")
expect(enterprise.is_producer).to be false
expect(enterprise.is_producer_only).to be false
end
end

context "when enterprise is_primary_producer and sells own" do
it "returns false" do
enterprise = build(:enterprise, is_primary_producer: true, sells: "own")
expect(enterprise.is_producer).to be false
expect(enterprise.is_producer_only).to be false
end
end
end
Expand Down