Skip to content

Commit

Permalink
feat: add support for sync price on Omni import
Browse files Browse the repository at this point in the history
Adding this feature allow usage of omni import with discount
  • Loading branch information
joamag committed Mar 14, 2021
1 parent ecc5fca commit 0e0a8f2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Support for the `invoiced` state at the `Order` model
* Storage of `company_product_code` inside `Product` and `Measurement` on import data
* Support for price fixing on Omni import

### Changed

Expand Down
9 changes: 7 additions & 2 deletions src/budy/models/bundle_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@
class BundleLine(base.BudyBase):

price = appier.field(
type = commons.Decimal
type = commons.Decimal,
observations = """The unit price for the item described by the
current line, the total should be calculated using this value"""
)

taxes = appier.field(
type = commons.Decimal
type = commons.Decimal,
observations = """The amount of taxes paid per each item in the
current line, this value is already included in the price value
of the line"""
)

currency = appier.field()
Expand Down
34 changes: 31 additions & 3 deletions src/budy/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,11 +1063,12 @@ def fix_closed_s(self):
name = "Import Omni",
parameters = (
("Invoice", "invoice", bool, True),
("Strict", "strict", bool, True)
("Strict", "strict", bool, True),
("Sync Prices", "sync_prices", bool, False)
),
level = 2
)
def import_omni_s(self, invoice = False, strict = True):
def import_omni_s(self, invoice = False, strict = True, sync_prices = False):
api = self.owner.get_omni_api()
appier.verify(
self.paid,
Expand Down Expand Up @@ -1206,6 +1207,33 @@ def import_omni_s(self, invoice = False, strict = True):
)
sale_lines.append(sale_line)

# in case the sync prices flag is set then the price
# value of the line must be checked in Omni to see if
# it's properly synced
if sync_prices:
store_merchandise = api.list_store_merchandise(
store_id,
**{
"filters[]" : [
"object_id:equals:%d" % line.merchandise.meta["object_id"]
]
}
)
appier.verify(
len(store_merchandise) > 0,
message = "Inventory line not found in Omni"
)
store_merchandise = store_merchandise[0]
is_different = not store_merchandise["retail_price"] == line.price
if is_different:
api.prices_merchandise([
dict(
object_id = line.merchandise.meta["object_id"],
retail_price = line.price,
functional_units = [store_id]
)
])

if self.shipping_cost > 0.0 and shipping_id:
sale_line = dict(
merchandise = dict(object_id = shipping_id),
Expand Down Expand Up @@ -1253,7 +1281,7 @@ def import_omni_s(self, invoice = False, strict = True):
if invoice:
# verifies that the current order is "invoiceable" so that
# no inconsistent information is going to be "created"
self.verify_invoiced()
if strict: self.verify_invoiced()

# issues the money sale slip in the Omni system, this is
# an expensive server-to-server operation
Expand Down

0 comments on commit 0e0a8f2

Please sign in to comment.