Merge pull request #30774 from ankush/postgres/stock
fix(postgres): minimum required changes for postgres builds
This commit is contained in:
commit
8d20da9b7a
@ -163,10 +163,15 @@ def get_party_details(party, party_type, args=None):
|
||||
def get_tax_template(posting_date, args):
|
||||
"""Get matching tax rule"""
|
||||
args = frappe._dict(args)
|
||||
from_date = to_date = posting_date
|
||||
if not posting_date:
|
||||
from_date = "1900-01-01"
|
||||
to_date = "4000-01-01"
|
||||
|
||||
conditions = [
|
||||
"""(from_date is null or from_date <= '{0}')
|
||||
and (to_date is null or to_date >= '{0}')""".format(
|
||||
posting_date
|
||||
and (to_date is null or to_date >= '{1}')""".format(
|
||||
from_date, to_date
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -831,9 +831,9 @@ def get_party_shipping_address(doctype, name):
|
||||
"where "
|
||||
"dl.link_doctype=%s "
|
||||
"and dl.link_name=%s "
|
||||
'and dl.parenttype="Address" '
|
||||
"and dl.parenttype='Address' "
|
||||
"and ifnull(ta.disabled, 0) = 0 and"
|
||||
'(ta.address_type="Shipping" or ta.is_shipping_address=1) '
|
||||
"(ta.address_type='Shipping' or ta.is_shipping_address=1) "
|
||||
"order by ta.is_shipping_address desc, ta.address_type desc limit 1",
|
||||
(doctype, name),
|
||||
)
|
||||
@ -881,11 +881,11 @@ def get_default_contact(doctype, name):
|
||||
"""
|
||||
SELECT dl.parent, c.is_primary_contact, c.is_billing_contact
|
||||
FROM `tabDynamic Link` dl
|
||||
INNER JOIN tabContact c ON c.name = dl.parent
|
||||
INNER JOIN `tabContact` c ON c.name = dl.parent
|
||||
WHERE
|
||||
dl.link_doctype=%s AND
|
||||
dl.link_name=%s AND
|
||||
dl.parenttype = "Contact"
|
||||
dl.parenttype = 'Contact'
|
||||
ORDER BY is_primary_contact DESC, is_billing_contact DESC
|
||||
""",
|
||||
(doctype, name),
|
||||
|
@ -54,11 +54,11 @@ class Opportunity(TransactionBase):
|
||||
self.calculate_totals()
|
||||
|
||||
def map_fields(self):
|
||||
for field in self.meta.fields:
|
||||
if not self.get(field.fieldname):
|
||||
for field in self.meta.get_valid_columns():
|
||||
if not self.get(field) and frappe.db.field_exists(self.opportunity_from, field):
|
||||
try:
|
||||
value = frappe.db.get_value(self.opportunity_from, self.party_name, field.fieldname)
|
||||
frappe.db.set(self, field.fieldname, value)
|
||||
value = frappe.db.get_value(self.opportunity_from, self.party_name, field)
|
||||
frappe.db.set(self, field, value)
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
|
@ -753,7 +753,7 @@ class BOM(WebsiteGenerator):
|
||||
bom_item.include_item_in_manufacturing,
|
||||
bom_item.sourced_by_supplier,
|
||||
bom_item.stock_qty / ifnull(bom.quantity, 1) AS qty_consumed_per_unit
|
||||
FROM `tabBOM Explosion Item` bom_item, tabBOM bom
|
||||
FROM `tabBOM Explosion Item` bom_item, `tabBOM` bom
|
||||
WHERE
|
||||
bom_item.parent = bom.name
|
||||
AND bom.name = %s
|
||||
|
@ -1219,7 +1219,7 @@ def make_fixtures(company=None):
|
||||
try:
|
||||
doc = frappe.get_doc(d)
|
||||
doc.flags.ignore_permissions = True
|
||||
doc.insert()
|
||||
doc.insert(ignore_if_duplicate=True)
|
||||
except frappe.NameError:
|
||||
frappe.clear_messages()
|
||||
except frappe.DuplicateEntryError:
|
||||
|
@ -5,6 +5,8 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder import Criterion
|
||||
from frappe.query_builder.functions import Cast_
|
||||
from frappe.utils import getdate
|
||||
|
||||
|
||||
@ -48,35 +50,57 @@ class ItemPrice(Document):
|
||||
)
|
||||
|
||||
def check_duplicates(self):
|
||||
conditions = (
|
||||
"""where item_code = %(item_code)s and price_list = %(price_list)s and name != %(name)s"""
|
||||
)
|
||||
|
||||
for field in [
|
||||
item_price = frappe.qb.DocType("Item Price")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(item_price)
|
||||
.select(item_price.price_list_rate)
|
||||
.where(
|
||||
(item_price.item_code == self.item_code)
|
||||
& (item_price.price_list == self.price_list)
|
||||
& (item_price.name != self.name)
|
||||
)
|
||||
)
|
||||
data_fields = (
|
||||
"uom",
|
||||
"valid_from",
|
||||
"valid_upto",
|
||||
"packing_unit",
|
||||
"customer",
|
||||
"supplier",
|
||||
"batch_no",
|
||||
]:
|
||||
if self.get(field):
|
||||
conditions += " and {0} = %({0})s ".format(field)
|
||||
else:
|
||||
conditions += "and (isnull({0}) or {0} = '')".format(field)
|
||||
|
||||
price_list_rate = frappe.db.sql(
|
||||
"""
|
||||
select price_list_rate
|
||||
from `tabItem Price`
|
||||
{conditions}
|
||||
""".format(
|
||||
conditions=conditions
|
||||
),
|
||||
self.as_dict(),
|
||||
)
|
||||
|
||||
number_fields = ["packing_unit"]
|
||||
|
||||
for field in data_fields:
|
||||
if self.get(field):
|
||||
query = query.where(item_price[field] == self.get(field))
|
||||
else:
|
||||
query = query.where(
|
||||
Criterion.any(
|
||||
[
|
||||
item_price[field].isnull(),
|
||||
Cast_(item_price[field], "varchar") == "",
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
for field in number_fields:
|
||||
if self.get(field):
|
||||
query = query.where(item_price[field] == self.get(field))
|
||||
else:
|
||||
query = query.where(
|
||||
Criterion.any(
|
||||
[
|
||||
item_price[field].isnull(),
|
||||
item_price[field] == 0,
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
price_list_rate = query.run(as_dict=True)
|
||||
|
||||
if price_list_rate:
|
||||
frappe.throw(
|
||||
_(
|
||||
|
@ -1167,7 +1167,7 @@ class StockEntry(StockController):
|
||||
from `tabItem` i LEFT JOIN `tabItem Default` id ON i.name=id.parent and id.company=%s
|
||||
where i.name=%s
|
||||
and i.disabled=0
|
||||
and (i.end_of_life is null or i.end_of_life='0000-00-00' or i.end_of_life > %s)""",
|
||||
and (i.end_of_life is null or i.end_of_life<'1900-01-01' or i.end_of_life > %s)""",
|
||||
(self.company, args.get("item_code"), nowdate()),
|
||||
as_dict=1,
|
||||
)
|
||||
|
@ -8,9 +8,8 @@ from typing import Optional, Set, Tuple
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.meta import get_field_precision
|
||||
from frappe.query_builder.functions import Sum
|
||||
from frappe.query_builder.functions import CombineDatetime, Sum
|
||||
from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, now, nowdate
|
||||
from pypika import CustomFunction
|
||||
|
||||
import erpnext
|
||||
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
|
||||
@ -1158,16 +1157,15 @@ def get_batch_incoming_rate(
|
||||
item_code, warehouse, batch_no, posting_date, posting_time, creation=None
|
||||
):
|
||||
|
||||
Timestamp = CustomFunction("timestamp", ["date", "time"])
|
||||
|
||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||
|
||||
timestamp_condition = Timestamp(sle.posting_date, sle.posting_time) < Timestamp(
|
||||
timestamp_condition = CombineDatetime(sle.posting_date, sle.posting_time) < CombineDatetime(
|
||||
posting_date, posting_time
|
||||
)
|
||||
if creation:
|
||||
timestamp_condition |= (
|
||||
Timestamp(sle.posting_date, sle.posting_time) == Timestamp(posting_date, posting_time)
|
||||
CombineDatetime(sle.posting_date, sle.posting_time)
|
||||
== CombineDatetime(posting_date, posting_time)
|
||||
) & (sle.creation < creation)
|
||||
|
||||
batch_details = (
|
||||
|
@ -7,6 +7,7 @@ from typing import Dict, Optional
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.query_builder.functions import CombineDatetime
|
||||
from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime
|
||||
|
||||
import erpnext
|
||||
@ -143,12 +144,10 @@ def get_stock_balance(
|
||||
|
||||
|
||||
def get_serial_nos_data_after_transactions(args):
|
||||
from pypika import CustomFunction
|
||||
|
||||
serial_nos = set()
|
||||
args = frappe._dict(args)
|
||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||
Timestamp = CustomFunction("timestamp", ["date", "time"])
|
||||
|
||||
stock_ledger_entries = (
|
||||
frappe.qb.from_(sle)
|
||||
@ -157,7 +156,8 @@ def get_serial_nos_data_after_transactions(args):
|
||||
(sle.item_code == args.item_code)
|
||||
& (sle.warehouse == args.warehouse)
|
||||
& (
|
||||
Timestamp(sle.posting_date, sle.posting_time) < Timestamp(args.posting_date, args.posting_time)
|
||||
CombineDatetime(sle.posting_date, sle.posting_time)
|
||||
< CombineDatetime(args.posting_date, args.posting_time)
|
||||
)
|
||||
& (sle.is_cancelled == 0)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user