mirror of
https://bitbucket.org/presik/trytonpsk-sale_shop.git
synced 2023-12-14 05:22:55 +01:00
Release v6.0
This commit is contained in:
parent
a19d93e995
commit
fadb77a671
14 changed files with 95 additions and 103 deletions
18
__init__.py
18
__init__.py
|
@ -2,15 +2,15 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
import shop
|
||||
import sale
|
||||
import user
|
||||
import configuration
|
||||
import stock
|
||||
import invoice
|
||||
import price_list
|
||||
import product
|
||||
import source
|
||||
from . import shop
|
||||
from . import sale
|
||||
from . import user
|
||||
from . import configuration
|
||||
from . import stock
|
||||
from . import invoice
|
||||
from . import price_list
|
||||
from . import product
|
||||
from . import source
|
||||
|
||||
|
||||
def register():
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
__all__ = ['Configuration']
|
||||
|
||||
|
||||
class Configuration(metaclass=PoolMeta):
|
||||
__name__ = 'sale.configuration'
|
||||
|
|
16
exceptions.py
Normal file
16
exceptions.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.model.exceptions import ValidationError
|
||||
|
||||
|
||||
class SaleMissingSequenceError(ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class ShopUserError(UserError):
|
||||
pass
|
||||
|
||||
|
||||
class SaleWriteError(UserError):
|
||||
pass
|
|
@ -5,8 +5,6 @@ from trytond.model import fields
|
|||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
|
||||
__all__ = ['Invoice', 'InvoicesStart', 'Invoices', 'InvoicesReport']
|
||||
|
||||
|
||||
class Invoice(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice'
|
||||
|
|
23
message.xml
Normal file
23
message.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data grouped="1">
|
||||
<record model="ir.message" id="msg_not_sale_shop">
|
||||
<field name="text">Go to user preferences and select a shop "%(s)"</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_no_return_sequence">
|
||||
<field name="text">Return Sale Sequence is missing!</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_sale_not_shop">
|
||||
<field name="text">Sale have not related a shop</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_edit_sale_by_shop">
|
||||
<field name="text">You cannot edit this order because you do not have permission to edit in this shop.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_sale_not_product">
|
||||
<field name="text">The sale "%(s)" dont have product </field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
|
@ -12,8 +12,6 @@ from trytond.wizard import (
|
|||
Wizard, StateView, StateReport, Button
|
||||
)
|
||||
|
||||
__all__ = ['PriceListLine']
|
||||
|
||||
|
||||
class PriceListLine(metaclass=PoolMeta):
|
||||
__name__ = 'product.price_list.line'
|
||||
|
@ -53,8 +51,8 @@ class ProductPriceList(Report):
|
|||
data=None
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(ProductPriceList, cls).get_context(records, data)
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super().get_context(records, header, data)
|
||||
for record in records:
|
||||
for l in record.lines:
|
||||
unit_price = l.product.list_price
|
||||
|
@ -118,9 +116,8 @@ class PriceListBySupplierReport(Report):
|
|||
__name__ = 'sale_shop.price_list_by_supplier_report'
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(PriceListBySupplierReport, cls).get_context(
|
||||
records, data)
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super().get_context(records, header, data)
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
ProductSupplier = pool.get('purchase.product_supplier')
|
||||
|
|
|
@ -7,8 +7,6 @@ from trytond.pyson import Eval
|
|||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.modules.product import price_digits
|
||||
|
||||
__all__ = ['UpdatePriceProductStart', 'UpdatePriceProduct']
|
||||
|
||||
|
||||
class Product(metaclass=PoolMeta):
|
||||
__name__ = 'product.product'
|
||||
|
|
103
sale.py
103
sale.py
|
@ -14,11 +14,10 @@ from trytond.report import Report
|
|||
from trytond.wizard import (
|
||||
Wizard, StateView, StateAction, StateReport, Button
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'Sale', 'SaleBySupplierStart', 'SaleBySupplier', 'SaleLine',
|
||||
'PrintSaleBySupplier',
|
||||
]
|
||||
from trytond.i18n import gettext
|
||||
from .exceptions import (SaleMissingSequenceError, ShopUserError,
|
||||
SaleWriteError)
|
||||
from trytond.modules.sale.exceptions import SaleValidationError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
_ZERO = Decimal('0.00')
|
||||
|
@ -189,6 +188,7 @@ class PrintSaleBySupplier(Wizard):
|
|||
shop_id = self.start.shop.id
|
||||
shop_name = self.start.shop.name
|
||||
data = {
|
||||
'ids': [],
|
||||
'company': self.start.company.id,
|
||||
'start_date': self.start.start_date,
|
||||
'end_date': self.start.end_date,
|
||||
|
@ -243,8 +243,8 @@ class SaleBySupplier(Report):
|
|||
return sum([l.quantity for l in lines]), start_date
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(SaleBySupplier, cls).get_context(records, data)
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super().get_context(records, header, data)
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
ProductSupplier = pool.get('purchase.product_supplier')
|
||||
|
@ -412,23 +412,11 @@ class Sale(metaclass=PoolMeta):
|
|||
cls.currency.states['readonly'] = Eval('state') != 'draft'
|
||||
cls.currency.depends.append('shop')
|
||||
|
||||
cls._error_messages.update({
|
||||
'not_sale_shop': (
|
||||
'Go to user preferences and select a shop ("%s")'),
|
||||
'no_return_sequence': (
|
||||
'Return Sale Sequence is missing!'),
|
||||
'sale_not_shop': (
|
||||
'Sale have not related a shop'),
|
||||
'edit_sale_by_shop': ('You cannot edit this order because you '
|
||||
'do not have permission to edit in this shop.'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
TableHandler = backend.get('TableHandler')
|
||||
table = TableHandler(cls, module_name)
|
||||
# if not table.column_exist('shop'):
|
||||
# table.add_raw_column(
|
||||
table_h = cls.__table_handler__(module_name)
|
||||
# if not table_h.column_exist('shop'):
|
||||
# table_h.add_raw_column(
|
||||
# 'shop',
|
||||
# cls.shop.sql_type(),
|
||||
# cls.shop.sql_format, None, None
|
||||
|
@ -440,8 +428,8 @@ class Sale(metaclass=PoolMeta):
|
|||
# 'UPDATE sale_sale set shop = 1;')
|
||||
|
||||
# Migration from 3.8: remove reference constraint
|
||||
if not table.column_exist('number'):
|
||||
table.drop_constraint('reference_uniq')
|
||||
if not table_h.column_exist('number'):
|
||||
table_h.drop_constraint('reference_uniq')
|
||||
|
||||
super(Sale, cls).__register__(module_name)
|
||||
|
||||
|
@ -452,38 +440,29 @@ class Sale(metaclass=PoolMeta):
|
|||
return user.shop.company.id if user.shop else \
|
||||
Transaction().context.get('company')
|
||||
|
||||
@fields.depends('company')
|
||||
def on_change_company(self):
|
||||
User = Pool().get('res.user')
|
||||
user = User(Transaction().user)
|
||||
if not user.shop:
|
||||
super(Sale, self).on_change_company()
|
||||
else:
|
||||
self.invoice_method = user.shop.sale_invoice_method
|
||||
self.shipment_method = user.shop.sale_shipment_method
|
||||
self.payment_term = user.shop.payment_term.id
|
||||
|
||||
@staticmethod
|
||||
def default_shop():
|
||||
User = Pool().get('res.user')
|
||||
user = User(Transaction().user)
|
||||
return user.shop.id if user.shop else None
|
||||
|
||||
@staticmethod
|
||||
def default_invoice_method():
|
||||
User = Pool().get('res.user')
|
||||
user = User(Transaction().user)
|
||||
if not user.shop:
|
||||
Config = Pool().get('sale.configuration')
|
||||
config = Config(1)
|
||||
return config.sale_invoice_method
|
||||
return user.shop.sale_invoice_method
|
||||
|
||||
@staticmethod
|
||||
def default_description():
|
||||
config = Pool().get('sale.configuration')(1)
|
||||
if config.default_description:
|
||||
return config.default_description
|
||||
|
||||
@staticmethod
|
||||
def default_shipment_method():
|
||||
User = Pool().get('res.user')
|
||||
user = User(Transaction().user)
|
||||
if not user.shop:
|
||||
Config = Pool().get('sale.configuration')
|
||||
config = Config(1)
|
||||
return config.sale_shipment_method
|
||||
return user.shop.sale_shipment_method
|
||||
|
||||
@staticmethod
|
||||
def default_warehouse():
|
||||
User = Pool().get('res.user')
|
||||
|
@ -500,12 +479,6 @@ class Sale(metaclass=PoolMeta):
|
|||
user = User(Transaction().user)
|
||||
return user.shop.price_list.id if user.shop else None
|
||||
|
||||
@staticmethod
|
||||
def default_payment_term():
|
||||
User = Pool().get('res.user')
|
||||
user = User(Transaction().user)
|
||||
return user.shop.payment_term.id if user.shop else None
|
||||
|
||||
@staticmethod
|
||||
def default_shop_address():
|
||||
User = Pool().get('res.user')
|
||||
|
@ -551,7 +524,6 @@ class Sale(metaclass=PoolMeta):
|
|||
Fill the number field with the sale shop or sale config sequence
|
||||
'''
|
||||
pool = Pool()
|
||||
Sequence = pool.get('ir.sequence')
|
||||
Config = pool.get('sale.configuration')
|
||||
User = Pool().get('res.user')
|
||||
config = Config(1)
|
||||
|
@ -561,15 +533,16 @@ class Sale(metaclass=PoolMeta):
|
|||
continue
|
||||
elif sale.shop:
|
||||
if sale.total_amount >= Decimal('0'):
|
||||
number = Sequence.get_id(sale.shop.sale_sequence.id)
|
||||
number = sale.shop.sale_sequence.get()
|
||||
else:
|
||||
if not sale.shop.sale_return_sequence:
|
||||
sale.raise_user_error('no_return_sequence')
|
||||
number = Sequence.get_id(sale.shop.sale_return_sequence.id)
|
||||
raise SaleMissingSequenceError(
|
||||
gettext('sale_shop.msg_no_return_sequence'))
|
||||
number = sale.shop.sale_return_sequence.get()
|
||||
elif user.shop:
|
||||
number = Sequence.get_id(user.shop.sale_sequence.id)
|
||||
number = user.shop.sale_sequence.get()
|
||||
else:
|
||||
number = Sequence.get_id(config.sale_sequence.id)
|
||||
number = config.sale_sequence.get()
|
||||
cls.write([sale], {
|
||||
'number': number,
|
||||
})
|
||||
|
@ -583,9 +556,8 @@ class Sale(metaclass=PoolMeta):
|
|||
vals = vals.copy()
|
||||
if not 'shop' in vals:
|
||||
if not user.shop:
|
||||
cls.raise_user_error('not_sale_shop', (
|
||||
user.rec_name,)
|
||||
)
|
||||
raise ShopUserError(
|
||||
gettext('sale_shop.not_sale_shop', s=user.rec_name))
|
||||
vals['shop'] = user.shop.id
|
||||
vlist2.append(vals)
|
||||
return super(Sale, cls).create(vlist2)
|
||||
|
@ -602,11 +574,10 @@ class Sale(metaclass=PoolMeta):
|
|||
for sales, _ in zip(actions, actions):
|
||||
for sale in sales:
|
||||
if not sale.shop:
|
||||
print('sale_shop error')
|
||||
cls.raise_user_error('sale_not_shop')
|
||||
raise SaleWriteError(
|
||||
gettext('sale_shop.msg_sale_not_shop'))
|
||||
if not sale.shop in user.shops:
|
||||
print('sele user error')
|
||||
cls.raise_user_error('edit_sale_by_shop')
|
||||
raise SaleWriteError(gettext('sale_shop.msg_edit_sale_by_shop'))
|
||||
super(Sale, cls).write(*args)
|
||||
|
||||
def _get_invoice_sale(self):
|
||||
|
@ -678,8 +649,8 @@ class SaleShopDetailedReport(Report):
|
|||
__name__ = 'sale_shop.report_sale_detailed'
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(SaleShopDetailedReport, cls).get_context(records, data)
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super().get_context(records, header, data)
|
||||
pool = Pool()
|
||||
|
||||
Sale = pool.get('sale.sale')
|
||||
|
@ -719,7 +690,7 @@ class SaleShopDetailedReport(Report):
|
|||
# amount_w_tax = []
|
||||
for line in start_lines:
|
||||
if line.type == 'line' and not line.product:
|
||||
Sale.raise_user_error('sale_not_product', line.sale.number)
|
||||
raise SaleValidationError(gettext('sale_shop.msg_sale_not_product', s=line.sale.number))
|
||||
|
||||
is_invoiced = False
|
||||
if line.sale.invoices:
|
||||
|
|
1
sale.xml
1
sale.xml
|
@ -52,6 +52,7 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
|||
</record>
|
||||
|
||||
<record model="ir.rule.group" id="rule_group_sale">
|
||||
<field name="name">Users in Shops</field>
|
||||
<field name="model" search="[('model', '=', 'sale.sale')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
</record>
|
||||
|
|
12
shop.py
12
shop.py
|
@ -2,13 +2,11 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval, Bool
|
||||
from trytond.pyson import Eval, Bool, Id
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond import backend
|
||||
|
||||
__all__ = ['SaleShop', 'SaleShopResUser']
|
||||
|
||||
|
||||
class SaleShop(ModelSQL, ModelView):
|
||||
'Sale Shop'
|
||||
|
@ -29,7 +27,7 @@ class SaleShop(ModelSQL, ModelView):
|
|||
'Sale Reference Sequence', domain=[
|
||||
('company', 'in', [Eval('context', {}).get('company', 0),
|
||||
None]),
|
||||
('code', '=', 'sale.sale'),
|
||||
('sequence_type', '=', Id('sale', 'sequence_type_sale')),
|
||||
], required=True)
|
||||
sale_invoice_method = fields.Selection([
|
||||
('manual', 'Manual'),
|
||||
|
@ -56,7 +54,7 @@ class SaleShop(ModelSQL, ModelView):
|
|||
'Sale Return Sequence', domain=[
|
||||
('company', 'in',
|
||||
[Eval('context', {}).get('company', -1), None]),
|
||||
('code', '=', 'sale.sale'),
|
||||
('sequence_type', '=', Id('sale', 'sequence_type_sale')),
|
||||
], required=True)
|
||||
salesmans = fields.Many2Many('sale.shop.company_employee', 'shop',
|
||||
'salesman', 'Salesmans')
|
||||
|
@ -70,15 +68,13 @@ class SaleShop(ModelSQL, ModelView):
|
|||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
pool = Pool()
|
||||
TableHandler = backend.get('TableHandler')
|
||||
Company = pool.get('company.company')
|
||||
shop_table = cls.__table__()
|
||||
company_table = Company.__table__()
|
||||
|
||||
super(SaleShop, cls).__register__(module_name)
|
||||
cursor = Transaction().connection.cursor()
|
||||
is_sqlite = 'backend.sqlite.table.TableHandler' in str(TableHandler)
|
||||
if not is_sqlite:
|
||||
if backend.name != 'sqlite':
|
||||
# SQLite doesn't support this query as it generates and update
|
||||
# with an alias (AS) which is not valid on SQLite
|
||||
query = shop_table.update(columns=[shop_table.currency],
|
||||
|
|
|
@ -6,8 +6,6 @@ from trytond.model import Workflow, ModelView, ModelSQL, fields
|
|||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['SaleSource']
|
||||
|
||||
STATES = {
|
||||
'readonly': (Eval('state') != 'draft')
|
||||
}
|
||||
|
|
2
stock.py
2
stock.py
|
@ -5,8 +5,6 @@ from trytond.model import fields
|
|||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
|
||||
__all__ = ['ShipmentOut', 'ShipmentOutReturn']
|
||||
|
||||
|
||||
class ShipmentOut(metaclass=PoolMeta):
|
||||
__name__ = 'stock.shipment.out'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=5.0.6
|
||||
version=6.0.0
|
||||
depends:
|
||||
ir
|
||||
company
|
||||
|
|
2
user.py
2
user.py
|
@ -5,8 +5,6 @@ from trytond.model import fields
|
|||
from trytond.pyson import Eval
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
__all__ = ['User']
|
||||
|
||||
|
||||
class User(metaclass=PoolMeta):
|
||||
__name__ = "res.user"
|
||||
|
|
Loading…
Reference in a new issue