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

Sale Amendment Factories #18

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
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
64 changes: 64 additions & 0 deletions src/trytond_factories/sale_amendment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
__all__ = [
"_SaleAmendmentLine",
"SaleAmendment",
"SaleLineAmendment",
]

import factory
import factory_trytond


class _SaleAmendmentLine(factory_trytond.TrytonFactory):
class Meta:
model = "sale.amendment.line"


class SaleAmendment(factory_trytond.TrytonFactory):
class Meta:
model = "sale.amendment"

sale = None

@factory.post_generation
def state(obj, create, extracted, **kwargs):
Model = obj.__class__
state_transitions = {
None: tuple(()),
"draft": tuple(()),
"requested": (Model.request,),
"validated": (
Model.request,
Model.validate_amendment,
),
}
return state_transitions[extracted]

@classmethod
def _after_postgeneration(cls, obj, create, results=None):
super()._after_postgeneration(obj, create, results)
if create and results:
for button in results["state"]:
button([obj])


class SaleLineAmendment(SaleAmendment):
class Params:
sale_line = None

sale = factory.SelfAttribute("sale_line.sale")

line = factory.RelatedFactory(
_SaleAmendmentLine,
factory_related_name="amendment",
action="line",
line=factory.SelfAttribute(
"factory_parent.sale_line"),
product=factory.SelfAttribute(
"factory_parent.sale_line.product"),
quantity=factory.SelfAttribute(
"factory_parent.sale_line.quantity"),
unit=factory.SelfAttribute(
"factory_parent.sale_line.unit"),
unit_price=factory.SelfAttribute(
"factory_parent.sale_line.unit_price"),
)