Add scale sync
This commit is contained in:
parent
3a9ab498b5
commit
6f140bc525
53
app/main.py
53
app/main.py
|
@ -45,6 +45,8 @@ try:
|
|||
except:
|
||||
from models import MODELS_RETAIL
|
||||
|
||||
from sync_scale import read_files_scale
|
||||
|
||||
invoice_type = []
|
||||
|
||||
_SALE_HISTORIC = [
|
||||
|
@ -1864,7 +1866,11 @@ class AppWindow(FrontWindow):
|
|||
self.dialog_historic_sales.exec_()
|
||||
|
||||
def action_search_sale(self):
|
||||
# self.print_no_commanded()
|
||||
if hasattr(self, 'activate_scale_sync') and self.activate_scale_sync:
|
||||
files = read_files_scale()
|
||||
for file in files:
|
||||
self.create_new_sale_from_scale(file)
|
||||
|
||||
self.dialog_search_sales.show()
|
||||
self.search_sales_by_domain()
|
||||
self.field_invoice_type.set_enabled(True)
|
||||
|
@ -2405,6 +2411,51 @@ class AppWindow(FrontWindow):
|
|||
if self.field_delivery_charge:
|
||||
self.field_delivery_charge.set_enabled(False)
|
||||
|
||||
def create_new_sale_from_scale(self, file):
|
||||
to_create = {
|
||||
'shop': self.shop['id'],
|
||||
'invoice_type': invoice_type[0][0],
|
||||
'company': self.company,
|
||||
'party': self.default_party['id'],
|
||||
'sale_device': self.device['id'],
|
||||
'payment_method': 'cash',
|
||||
'payment_term': self.default_payment_term['id'],
|
||||
'kind': 'take_away',
|
||||
'reference': file['ticket'],
|
||||
'turn': 1,
|
||||
}
|
||||
|
||||
_sale = self.Sale.new_sale(to_create)
|
||||
print('sale created...', _sale)
|
||||
|
||||
def _add_products():
|
||||
for _line in file['lines']:
|
||||
_code = _line['product']
|
||||
dom = [('code', '=', _code)]
|
||||
products = self.Product.find(
|
||||
dom,
|
||||
fields=['id', 'name', 'code', 'description']
|
||||
)
|
||||
if not products:
|
||||
print('Producto no encontrado ...', _code)
|
||||
return
|
||||
else:
|
||||
product = products[0]
|
||||
|
||||
qty = Decimal(int(_line['weight']) / 1000)
|
||||
print('sale qty...', qty, product)
|
||||
|
||||
data = {
|
||||
'sale_id': _sale['id'],
|
||||
'product_id': product['id'],
|
||||
'qty': qty
|
||||
}
|
||||
|
||||
res = self.Sale.faster_add_product(data)
|
||||
print('res ....producto creado ...', res)
|
||||
_add_products()
|
||||
|
||||
|
||||
def create_new_sale(self, kind='take_away'):
|
||||
if self.type_pos_user == 'cashier':
|
||||
self.message_bar.set('not_sale')
|
||||
|
|
Loading…
Reference in New Issue